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 trialvincenzo IEVA
Front End Web Development Techdegree Graduate 14,211 Pointsspread operator in this case
Hi,
can someone help me understand what the spread operator does in this case? [...arr, ...innerMovies]
thanks
1 Answer
Steven Parker
231,268 PointsWhat the spread operator itself does is to convert a collection of items into its individual elements. In your example, "arr
" is an array with potentially several elements; and "...arr
" is the elements all listed out as separate items.
This lets you do things in one step that would otherwise require loops, such as your example of re-combining multiple arrays into a single one.
Andrey Misikhin
16,529 PointsAndrey Misikhin
16,529 PointsIt is concatenation of two arrays. For example,
If you will do it, than you will see, that you received a new array, that consists of previous two.
[1, 2, 3, 'a', 'b', 'c']