destructuring array from object code example
Example 1: 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);
Example 2: array destructuring in javascript
const array = ['ismail', 'sulman'];
const [firstElement, secondElement] = array;
console.log(firstElement, secondElement);
const secondArray = ['ismail', 'naeem', 'Mr', 1];
const [firstEl, secondEl, ...array1] = secondArray;
console.log(firstEl, secondEl, array1);