JavaScript Array Basics Cheat Sheet
What is an Array?
JavaScript arrays are ordered collections of values accessible by numeric indices. They can store multiple data types
including numbers, strings, booleans, objects, and other arrays.
Accessing Elements
Use square brackets and zero-based indexing:
array[0] // first item
array[10] // undefined if out of bounds
Array Properties
[Link] returns the number of elements.
Updating Elements
array[index] = newValue; // Updates element at index
Two-Dimensional Arrays
An array of arrays, used for grid-like data:
array[row][col]
Destructuring Arrays
[a, b] = array; // Assigns values
[a, b, ...rest] = array; // Collects remaining items
Common Methods
push() - Add to end
pop() - Remove from end
shift() - Remove from start
unshift() - Add to start
indexOf() - Find index
splice() - Add/remove at index
includes() - Check existence
concat() - Merge arrays
slice() - Copy a portion
reverse() - Reverse in place
join() - Join into string
split() - String to array
spread (...) - Copy or expand
Spread Syntax
JavaScript Array Basics Cheat Sheet
[...arr] creates a shallow copy of an array.
Example
const fruits = ['apple', 'banana'];
[Link]('mango');
[Link](fruits); // ['apple', 'banana', 'mango']