Flash cards
Review the key moves
What is the main idea behind React ES6 Spread Operator?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
___ numbersOne = [1, 2, 3];Put the learning moves in the order that makes the concept easiest to apply.
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.