Example 1: spread operator in javascript
let numList = [1,2,3];
let numListClone = [...numList];
let animal = {
name: 'dog',
color: 'brown',
age: 7
};
let { age, ...otherProperties } = animal;
function sum(x, y, ...rest) {}
let numLists = [...numList1, ...numList2];
let animalWithBreed = {
...animal,
breed: '',
}
Example 2: spread operator javascript
obj = {first_name : "Marty",
lovers: ["Jennifer Parker","Baines McFly"]
};
let objClone = { ...obj };
console.log(objClone)
Example 3: spread operator javascript
const parts = ['shoulders', 'knees'];
const lyrics = ['head', ...parts, 'and', 'toes'];
Example 4: spread operator
function sum(x, y, z) {
return x + y + z;
}
const numbers = [1, 2, 3];
console.log(sum(...numbers));
console.log(sum.apply(null, numbers));
Example 5: javascript spread operator
function sum(x, y, z) {
return x + y + z;
}
const numbers = [1, 2, 3];
console.log(sum(...numbers));
console.log(sum.apply(null, numbers));
Example 6: spread operator javascript
[a, b, ...objIteravel] = [1, 2, 3, 4, 5];