JavaScript Array Methods Cheat Sheet

All JavaScript array methods at a glance — iteration, transformation, search, mutation, and ES2022+ additions.

Iteration Search Mutation Create / Transform Sorting

Iteration

MethodReturnsDescription
arr.forEach(fn) void Execute fn for each element (no return)
arr.map(fn) Array New array of fn(element) results
arr.filter(fn) Array New array of elements where fn returns true
arr.reduce(fn, init) any Accumulate to a single value left-to-right
arr.reduceRight(fn, init) any Accumulate right-to-left
arr.every(fn) boolean True if fn returns true for ALL elements
arr.some(fn) boolean True if fn returns true for ANY element
arr.flatMap(fn) Array map() then flatten one level (ES2019)

Mutation (modifies original)

MethodReturnsDescription
arr.push(...items) length Add items to end, return new length
arr.pop() element Remove and return last element
arr.unshift(...items) length Add items to beginning
arr.shift() element Remove and return first element
arr.splice(i, n, ...) Array Remove n items at i, optionally insert replacements
arr.fill(val, s, e) Array Fill with val from index s to e
arr.reverse() Array Reverse array in place
arr.sort(compareFn) Array Sort in place; use (a,b) => a-b for numbers

Create & Transform (non-mutating)

MethodReturnsDescription
arr.slice(s, e) Array Shallow copy from index s to e (exclusive)
arr.concat(...arrays) Array Merge arrays into new array
arr.flat(depth) Array Flatten nested arrays to given depth (default 1)
arr.join(sep) string Join elements into string with separator
arr.toReversed() Array Reversed copy, no mutation (ES2023)
arr.toSorted(fn) Array Sorted copy, no mutation (ES2023)
Array.from(iter, fn) Array Create array from iterable/array-like
Array.of(...items) Array Create array from arguments

Sorting Patterns

arr.sort((a,b) => a-b) Sort numbers ascending
arr.sort((a,b) => b-a) Sort numbers descending
arr.sort((a,b) => a.localeCompare(b)) Sort strings alphabetically
arr.sort((a,b) => a.name < b.name ? -1 : 1) Sort objects by string property
[...new Set(arr)] Remove duplicates (primitive values)

More Cheat Sheets