Good piece, thanks! I've known about the spread operator for a little while, but it hasn't yet made its way into my reach-for arsenal. I don't seem to remember to use it at the opportune times. Do you find there's a particular use case where it clicked for you?
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Yup! Check out this post if you want that example specifically. It's essentially grabbing each element in the array and dropping it into a new array structure.
Good piece, thanks! I've known about the spread operator for a little while, but it hasn't yet made its way into my reach-for arsenal. I don't seem to remember to use it at the opportune times. Do you find there's a particular use case where it clicked for you?
Probably my most common use case is merging an array or object into something I'm defining. Like so:
You said that it always creates an array, right? Would the result be
[[1,2,3,4], 6,7,10]
?...Oh, nevermind, just tried it in the console! It flattens it; that makes a lot of sense!
Yup! Check out this post if you want that example specifically. It's essentially grabbing each element in the array and dropping it into a new array structure.
5 Uses for the Spread Operator
Laurie ・ Jul 10 ・ 3 min read