DESTRUCT an array code example
Example 1: destructure array javascript
var [first, second, ...rest] = ["Mercury", "Earth", ...planets, "Saturn"];
Example 2: destructuring assignment
Destructuring assignment is special syntax introduced in ES6,
for neatly assigning values taken directly from an object.
const user = { name: 'John Doe', age: 34 };
const { name, age } = user;
Example 3: object destructuring
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 4: destructure to object
({x: oof.x, y: oof.y} = foo);
Example 5: 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);