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

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.