JavaScript Spread Operator

JavaScript Spread Operator

 

const array =[1,2,3,4];
const arrayTwo = [...array, 4];
console.log(arrayTwo);


const person = {
name:'Brad',
age:36
}

const newPerson = {
...person,
email: '[email protected]'
}

console.log(newPerson);

You can also use filter and stroe values in new array

const arrayThree = [...array.filter(num => num !== 2)];
console.log(arrayThree);

 

Leave a Reply

Your email address will not be published. Required fields are marked *