Passing Arguments Using Spread
The spread (...
) syntax in javascript allows an iterable (array, strings, or object literals)
to expand in places where zero or more arguments are expected.
Let’s see a quick example of what exactly is meant by this. In the below example we have two arrays that we combine. One using spread and one not:
We can see the difference in that using the spread syntax it expands the array so when we combine the arrays they do not become nested because the array itself is unpacked.
A handy usage of this can be seen when copying arrays. Using the spread syntax makes a shallow copy of the array.
The spread syntax also allows you to more easily concatenate an array.
Read more about it here