How the spread operator lets you read over lists of values with less effort
The spread operator is represented by three dots, such as
.... Its basic use is to read over lists of values or properties, such as for objects and arrays. This translates into two basic uses:
Copying and Overwriting Array/Object Values
If you have an array or object, you can use a spread operator to quickly copy all the values over to another variable. This lets you selectively overwrite different properties and values for objects.
Taking Multiple Arguments
When defining a function, you can set a spread operator as a parameter to define a list of values of unspecified length.
You can then treat
arguments as an array with things like
.reduce. You can also place other paramters before it that aren’t spread operators.
This is great if you need an unspecified number of optional values for a function, while including some regular named arguments first.