Spread Syntax
The spread syntax allow an object, such as an array or string, to spread to expand in place where zero or more arguments are expected. An object expression can also be expanded in place where zero or more key-value pairs are expected.
The advantage of the spread syntax is that a declarative approach can be used to modify the literal array instead of an imperative approach that programmatically creates the new array.
Use Cases
Inserting into literal arrays
Copying an array
It is important to understand that the spread syntax only goes one level deep, so that if you are copying the contents of an array that contains objects, rather than primitive values, you will be copying the reference to the objects and therefore both arrays will refer to the same objects.
Passing Multiple Values to a Function
Combining two objects
Adding new fields to an object
Updating the value of a subset of the fields after initial values have been set
Last updated
Was this helpful?