rest and spread operator in javascript code example
Example 1: spread and rest javascript
var myName = ["Marina" , "Magdy" , "Shafiq"];var newArr = [...myName ,"FrontEnd" , 24];console.log(newArr) ;
Example 2: 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 3: the rest operator javascript
function sum(...numbers) {
return numbers.reduce((accumulator, current) => {
return accumulator += current;
});
};
sum(1,2)
sum(1,2,3,4,5)
Example 4: spread and rest javascript
var myName = ["Marina" , "Magdy" , "Shafiq"] ;const [firstName , ...familyName] = myName ;console.log(firstName);
Example 5: spread operator javascript
[a, b, ...objIteravel] = [1, 2, 3, 4, 5];
Example 6: spread and rest operator javascript
function myData(...args){console.log(args) ;