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: array spread operator in javascript
let arr1 = ['A', 'B', 'C'];
let arr2 = ['X', 'Y', 'Z'];
let result = [...arr1, ...arr2];
console.log(result);
Example 3: spread operator javascript
const parts = ['shoulders', 'knees'];
const lyrics = ['head', ...parts, 'and', 'toes'];
Example 4: 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 5: spread operator javascript
[a, b, ...objIteravel] = [1, 2, 3, 4, 5];
Example 6: javascript spread operator
function myFunction(v, w, x, y, z) { }
let args = [0, 1];
myFunction(-1, ...args, 2, ...[3]);