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!
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
Samuel KleosFront End Web Development Techdegree Student 11,860 Points
Why use the spread operator when you can use join()?
Arent these the same thing?
let new_array = [ ...old_array ];
let new_array = [ old_array.join(', ')];
Steven Parker224,936 Points
These lines produce different results. In the first example, the spread operator will create a copy of the old array. But in the second example, the join method will create an array with just one element, and that element will be a string containing a comma-separated list of the old array's values.
array.join() function returns the array in to a string to be readable on witch way you want(like you putted in a ", "), so when you want to display the array then you might use join, but here your just structuring the array so should not use join because you might use the array on a different way and then the join will disturb you to return a functional return because its built with the commas and spaces extra then a normal raw array.
I hope this helps you