Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
PLUS
William Li
Courses Plus Student 26,868 Points

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

typeof([3,2,4].toString())
==> "string"