Example 1: destructure array javascript
var [first, second, ...rest] = ["Mercury", "Earth", ...planets, "Saturn"];
Example 2: array destructuring
const myArray = ["a", "b", "c"];
const x = myArray[0];
const y = myArray[1];
console.log(x, y);
const myArray = ["a", "b", "c"];
const [x, y] = myArray;
console.log(x, y);
Example 3: javascript function destructuring
function f() {
return [1, 2];
}
let a, b;
[a, b] = f();
console.log(a);
console.log(b);
Example 4: destructuring Array in JavaScript
function getArray() {
return ["Hello", "I" , "am", "Sarah"];
}
let [greeting,pronoun] = getArray();
console.log(greeting);
console.log(pronoun);
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);
Example 6: destructuring es6 freecodecamp
const iceCreamFlavors = ['hazelnut', 'pistachio', 'tiramisu'];const flavor1 = iceCreamFlavors[0];const flavor2 = iceCreamFlavors[1];const flavor3 = iceCreamFlavors[2];console.log(flavor1, flavor2, flavor3);