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 trialhakan Gülay
8,489 Pointsquestion
Hi,
the code which is in this video is
var my_array=[2,3,4]
console.log(my_array.toString());
my_array.push(5);
console.log(my_array.toString());
the video shows us if we dont put toString
into console.log, it shows
2,3,4
2,3,4,5
but I used this code on subline text3 I dont need to use toString. when ı use it and I dont use it they show me different result,like
[2,3,4]
[2,3,4,5]
why? can you please tell me ?
http://teamtreehouse.com/library/javascript-foundations/arrays/methods-part-1
1 Answer
Chris Malcolm
2,909 PointstoString ill convert it to a string..simply by taking each object and putting a comma (,) between. then console will print this basic string.
Result:
2,3,4
2,3,4,5
If you don't do toString, yes it will still work, but then console.log method takes the raw array and displays it with brackets and colors.
Result:
[2,3,4]
[2,3,4,5]
you can think of these two methods as doing the same thing i.e. displaying the contents, but with different string formats.
hakan Gülay
8,489 Pointshakan Gülay
8,489 Pointssorry it shows 2,3,4 2,3,4,5 when ı use "toString"