Theme
Primary Color
Lesson 15

Destructuring Array Part 2

محتوى الدرس

main.js
/*
  Destructuring
  - Object
  - Array
  - Parameter
*/

// First Example

const food = ["Burger", "Pizza", "Chicken", ["Apple", "Banana", "Mango", ['EgyOrange', "PakistanOrange"]]];

const [one, two, three, [fr1, fr2, , [o1, o2]]] = food;

console.log(`The Food I Love Is: ${one}, ${two}, ${three}.`);
console.log(`The Fruits I Love Is: ${fr1}, ${fr2}, ${three}`);
console.log(`And I Love All Kinds Of Orange Specially ${o1}, ${o2}`);

// ###########################

// Second Example

const food = ["Burger", "Pizza", "Chicken", "Apple", "Banana", "Mango", "Rice", "Meat"];

const [one, two, three, ...otherFood] = food;

console.log(`The Food I Love Is: ${one}, ${two}, ${three}, ${otherFood}`);