spread operator in object code example
Example 1: spread operator javascript object
let obj1 = { foo: 'bar', x: 42 };
let obj2 = { foo: 'baz', y: 13 };
let clonedObj = { ...obj1 };
// Object { foo: "bar", x: 42 }
let mergedObj = { ...obj1, ...obj2 };
// Object { foo: "baz", x: 42, y: 13 }
Example 2: es6 spread
const numbers = [43, 3, 11, 54];
const max = Math.max(...numbers); // Spreads numbers as parameters
// max is 54