Spread Operator
The JavaScript spread operator ( ... ) copies all or part of an existing array or object into another array or object.
Example
const numbersOne = [1, 2, 3];
const numbersTwo = [4, 5, 6];
const numbersCombined = [...numbersOne, ...numbersTwo];The spread operator is often used in combination with destructuring.
numbersWe can use the spread operator with objects too:
Example
const car = {
brand: 'Ford', model: 'Mustang', color: 'red'
}
const car_more = {
type: 'car', year: 2021, color: 'yellow'
}
const mycar = {...car, ...car_more}Notice that the properties that did not match were added, and the property that did match was overwritten by the last object.