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

Kartik Kapoor
Kartik Kapoor
3,016 Points

What is the need for using consol.log(my_array.toString()); ?

I see what difference it is making to the output but why is this happening?Why are we not getting the expexted result with " console.log(my_array); " ?

Dor Bar
Dor Bar
8,410 Points

Because you need to be precise, you need to write exactly what do you want to execute.

Zachary Green
Zachary Green
16,359 Points

this is one of the fundumentals of programing langs. there are types of data and each type is treated differently. console.log() outputs a string. an array is not a string there for theres a method to treat an array and other data types as strings.

1 Answer

Rhonda Kate Johnson
Rhonda Kate Johnson
4,756 Points

I was curious about this too. I looked at a similar question for this lesson, and it seems we have to convert the array to a string because of a bug in certain browsers. Some browser versions (especially older ones) won't display the console.log for arrays properly, and so that's why our teacher has us convert it to a string. However, I think a lot of newer browser versions have corrected the issue, so that's why you might display console.log for an array properly without converting to a string.