–––––––––––––––––––––––––––––––––––––––––––––––––– -->
My latest post on JavaScript - Spread operator fully explained is here.
It expands an iterable object into the list of arguments. (Arrays, Objects, Strings )
When …arr is used in the function call, it ‘expands’ an iterable object arr into the list of arguments.
1 | const arr = [34, 22, 13, 3] |
Making a copy of an array object.
1 | const arr = [34,22,13,3] |
Concatenating Arrays & Combining objects
1 | // combining arrays |
1 | // combining objects |
Passing the array into the Math.max() function doesn’t work but using the spread operator spreads the array into individual elements of the array.
1 | const arr = [1,2,3,4] |
Even though both of them have the same syntax”…”.
Both of them are the exact opposite of each other.
The Rest Parameter casts a list of items into an array and the spread operator expands an iterable object into its individual elements.
JavaScript, Operator, WebDev — Nov 24, 2020