javascript rest vs spread operator code example
Example 1: javascript rest parameters vs spread operator
function foo (...args) { console.log(args) }
foo(1,2,3,4,5,6)
let arr = [1, 2, 3];
let arrCopy = [-1, 0, ...arr];
Example 2: spread and rest javascript
var myName = ["Marina" , "Magdy" , "Shafiq"];var newArr = [...myName ,"FrontEnd" , 24];console.log(newArr) ;
Example 3: spread and rest operator javascript
var myName = ["Marina" , "Magdy" , "Shafiq"] ;const [firstName , ...familyName] = myName ;console.log(firstName);
Example 4: spread and rest operator javascript
function myData(...args){console.log(args) ;