JavaScript arrays have 30+ built-in methods. This is a practical reference organized by what they do — not just a list of signatures. Every method includes a runnable example showing why you'd reach for it.
1. Adding & Removing Elements
push(...items) / pop() — End of Array (Stack)
Loading editor...
Both mutate the array. push returns the new length; pop returns the removed element.
unshift(...items) / shift() — Beginning of Array (Queue)
Loading editor...
O(N) — all elements shift. push/pop are O(1) and preferred for performance.
splice(start, deleteCount?, ...items) — Insert / Remove Anywhere
Loading editor...
splice mutates and returns the removed elements.
2. Non-Mutating Access & Slicing
slice(start?, end?) — Extract a Portion
Loading editor...
Interview use: Extracting everything except the last item (slice(0, -1) in listFormat), shallow cloning.
join(separator?) — Array → String
Loading editor...
Interview use: Turning class name arrays into strings (classnames), building list strings (listFormat).
concat(...values) — Merge Arrays
Loading editor...
Does not mutate. Spread [...a, ...b] is the modern alternative.
3. Searching & Finding
indexOf(value, fromIndex?) / lastIndexOf(value) — Position
Loading editor...
Uses === comparison. Cannot find NaN (NaN !== NaN).
includes(value, fromIndex?) — Contains Check
Loading editor...
Interview use: Checking if a value exists (multi-value filter, class name dedup).
find(callback) / findIndex(callback) — First Match
Loading editor...
Returns the first match, not all matches. Use filter for all matches.
filter(callback) / some(callback) / every(callback) — Condition Tests
Loading editor...
Interview use: filter in data selection (#30), some in OR filter groups, every for multi-class matching (#24 DOM traversal).
4. Transforming (Non-Mutating)
map(callback) — Transform Each Element
Loading editor...
Returns a new array of the same length. Interview use: Deep cloning arrays, transforming data, generating JSX.
reduce(callback, initialValue?) — Accumulate
Loading editor...
Interview use: countBy, groupBy, data merging, flatten one-liner.
flat(depth?) / flatMap(callback) — Flatten
Loading editor...
Interview use: Interview #12 flatten implementation, transforming and flattening in one pass.
5. Sorting & Ordering
sort(compareFn?) — In-Place Sort
Loading editor...
Mutates the original. Clone first with [...arr] if you need immutability.
reverse() — In-Place Reverse
Loading editor...
6. Iteration Methods
forEach(callback) — Loop with Side Effects
Loading editor...
No return value. Cannot break early. Prefer for...of if you need break/continue.
7. Utility Methods
Array.isArray(value) — Type Check
Loading editor...
The only reliable way to check if something is an array. typeof [] returns 'object'.
Array.from(iterable, mapFn?) — Create from Iterable
Loading editor...
Array.of(...items) — Create from Arguments
Loading editor...
Mutation vs Non-Mutation Summary
| Mutates | Does NOT Mutate |
|---|---|
| push, pop, shift, unshift, splice, sort, reverse, fill, copyWithin | slice, concat, join, map, filter, reduce, find, findIndex, indexOf, includes, some, every, flat, flatMap, forEach, entries, keys, values |
Interview Tips
- Clone before mutating —
[...arr].sort()notarr.sort()if you need the original. includesfinds NaN —indexOfdoesn't. Know the difference.spliceis the Swiss Army knife — insert, remove, and replace all in one call.reducecan build anything — objects, arrays, maps — it's the most general array method.