array destructure javascript es6 code example
Example 1: destructuring arrays with rest operator
const [q, r, ...callThisAnythingYouWant] = [1, 2, 3, 4, 5, 6, 7, 8];
console.log(q, r);
console.log(callThisAnythingYouWant);
Example 2: javascript object destructuring
let obj = {name: 'Max', age: 22, address: 'Delhi'};
const {name, age} = obj;
console.log(name);
console.log(age);
console.log(address);
let a, b, rest;
[a, b] = [10, 20];
console.log(a);
console.log(b);
[a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(rest);