Welcome to the Treehouse Community
Looking to learn something new?
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)
William LiCourses Plus Student 26,865 Points
Yes, toString() method basically convert your Array into a String.
typeof([3,2,4].toString()) ==> "string"