Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Foundations Arrays Methods: Part 1

Array returns with .toString() method

I know that the PUSH adds a string to the end of the existing array, taking the [2, 3, 4] and making it [2, 3, 4, 5]. I also understand the reason for using the "my_arrray.toString()" method with the PUSH demonstration to keep the console.log from goofing up. BUT, I am curious about the appearance of the results.

With the .toString() method added, the array appears WITHOUT square brackets...

 2, 3, 4
 2, 3, 4, 5

But without the .toString() method added, they appear with square brackets...

 [2, 3, 4, 5]
 [2, 3, 4, 5]

Does this effect anything? Is this just a representational goof in the console.log? I didn't find any specific info about it on the w3schools.com page about Array .toString() method (http://www.w3schools.com/jsref/jsref_tostring_array.asp)

1 Answer

William Li
William Li
Courses Plus Student 26,865 Points

Yes, toString() method basically convert your Array into a String.

==> "string"