Array Basics in JavaScript
From the JavaScript cheat sheet · Objects & Arrays · verified Jul 2026
Array Basics
Creating and manipulating arrays
javascript
// Array creation
const arr = [1, 2, 3];
const mixed = [1, 'two', true, null];
// Accessing elements
arr[0]; // 1
arr.at(-1); // 3 (last element)
// Length and modification
arr.length; // 3
arr.push(4); // add to end
arr.pop(); // remove from end
arr.unshift(0); // add to beginning
arr.shift(); // remove from beginning💡 Use at() for negative indexing to access from end
⚡ push/pop are faster than unshift/shift
📌 splice mutates original, slice returns new array
🟢 See also: Array Methods sheet for map, filter, reduce, find, sort, and 20+ more methods