Spread Syntax
Use Cases
Inserting into literal arrays
let array1 = [1, 2, 3];
let array2 = [4, 5, 6];
// inserting at the end
let newArray = [...array1, ...array2];
console.log(newArray); // [1,2,3,4,5,6]
// inserting at the beginning
newArray = [...array2, ...array1];
console.log(newArray); // [1,2,3,4,5,6]
Copying an array
let array1 = [1, 2, 3];
let array2 = [...array1];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