An array is a special data structure in JavaScript used to store multiple values in a single variable. Think of it like a train π where each compartment holds a different passenger (data).
let num1, num2, num3
), we store values in a single array.0
) to access elements.let fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits[0]); // "Apple" (First element)
console.log(fruits[2]); // "Cherry" (Third element)
Now, letβs explore essential array methods with fun explanations & examples!
...
) β Expanding Arrays Like Magic π©The spread operator (...
) allows you to expand an array into individual elements. Imagine unpacking a suitcase π§³ where each item is laid out separately.