About Lesson
Array Destructuring
Array destructuring allows you to unpack values from arrays into distinct variables.
Example:
JavaScript
let fruits = ["Apple", "Banana", "Mango"];
let [firstFruit, secondFruit] = fruits;
console.log(firstFruit); // Output: Apple
console.log(secondFruit); // Output: Banana
You can also skip elements or assign default values.
Example:
JavaScript
let [firstFruit, , thirdFruit] = fruits;
console.log(thirdFruit); // Output: Mango