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 Displaying the Content

Do you need to use join() method to convert array of values to a string ?

Why don't you need to convert the options array into a string using the join method, like so:

select.innerHTML=options.join(' ');
Van Tran Huu
Van Tran Huu
16,248 Points

I think we need both map() & join() in this case

1 Answer

Steven Parker
Steven Parker
216,744 Points

Apparently, assigning an array to "innerHTML" causes the system to perform type coercion to make it into a string. The default conversion adds comma separators, but they don't seem to be displayed in the select list on a typical browser.

I believe an explicit "join" with an empty string separator would be preferable even if not essential for creating the display. Perhaps it was omitted unintentionally.

Maybe if I tag him, Guil Hernandez will comment.