Code Examples
// 1. Array literal (most common)
const fruits = ['apple', 'banana', 'cherry'];
// 2. Array constructor
const nums = new Array(1, 2, 3, 4, 5);
// 3. Array.from() — convert iterable to array
const letters = Array.from('hello'); // ['h','e','l','l'...
const colors = ['red', 'green', 'blue', 'yellow'];
// Access by index (0-based)
colors[0]; // 'red'
colors[2]; // 'blue'
colors[colors.length - 1]; // 'yellow' — last element
// Modern: .at() method — supports negative indexing!...
const arr = [1, 2, 3];
// push — add to END, returns new length
arr.push(4, 5); // arr = [1,2,3,4,5]
// pop — remove from END, returns removed item
const last = arr.pop(); // last=5, arr=[1,2,3,4]
// unshift — add to BEGINNING
arr.unshift...