Master ordered lists, zero-based array indexing, array mutability, stack methods, and key array element inspection techniques.
Learn how variables act as labeled containers for data using const, let, and var to manage lexical scope and reassignment safely in modern applications.
An array is an ordered list of values enclosed in square brackets [...]. Array elements can hold any data type, numbers, strings, objects, or even nested arrays.
Arrays store sequences of data (user lists, product catalogs, order items) accessible by 0-based numerical index positions.
Array positions start at index 0 (first item = arr[0]). You can find the last item using arr[arr.length - 1] or modern arr.at(-1):
const fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits[0]); // "Apple" (First element)
console.log(fruits[1]); // "Banana" (Second element)
console.log(fruits.length); // 3
console.log(fruits.at(-1)); // "Cherry" (Last element)
// Modifying array contents
fruits.push("Dragonfruit"); // Add item to end
console.log(fruits.length); // 4
push(item): Add to end of array.pop(): Remove item from end of array.unshift(item): Add item to start of array.shift(): Remove item from start of array.const stack = [10, 20];
stack.push(30); // [10, 20, 30]
stack.pop(); // Returns 30 -> [10, 20]
fruits[99]) returns undefined rather than throwing an error. Always check .length or verify array bounds.length = 5 has valid indices from 0 to 4. Accessing arr[5] returns undefined!Arrays store ordered lists. Next, let's explore Objects for key-value records!