array destructring in js code example
Example 1: array destructuring
//Without destructuring
const myArray = ["a", "b", "c"];
const x = myArray[0];
const y = myArray[1];
console.log(x, y); // "a" "b"
//With destructuring
const myArray = ["a", "b", "c"];
const [x, y] = myArray; // That's it !
console.log(x, y); // "a" "b"
Example 2: 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);