When I first stumbled upon the
MDN says that:
"Spread syntax allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected."
Pretty simple, no? In plain English this means that this operator spreads the items inside an iterable (be it string, array, set or anything that we can loop through really) inside a receiver (a receiver is something that receives the spread values).
Now that we got the definition out of the way, what exactly can we do with this operator?
2. Copy an array and add new elements to it
This works with arrays holding different types or mixed arrays, like so.
4. Spread elements on function calls
Oldest comments (0)