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
206,336 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.