React Tutorials
React ES6
React Hooks
JavaScript spread operator (...
) allows us to quickly copy all or part of the same existing members or object to another organization or object.
const numbersOne = [1, 2, 3];
const numbersTwo = [4, 5, 6];
const numbersCombined = [...numbersOne, ...numbersTwo];
The distribution operator is often used in conjunction with demolition.
Assign the first and second items from numbers
to variables and put the rest in an array:
const numbers = [1, 2, 3, 4, 5, 6];
const [one, two, ...rest] = numbers;
We may also use the distribution operator and materials:
Combine these two objects:
const myVehicle = {
brand: 'Ford',
model: 'Mustang',
color: 'red'
}
const updateMyVehicle = {
type: 'car',
year: 2021,
color: 'yellow'
}
const myUpdatedVehicle = {...myVehicle, ...updateMyVehicle}
Note that incompatible structures are included, but a similar element, color
, was written over the last transfer item, updateMyVehicle
. The resulting color is now yellow.