JavaScript Array Methods Cheat Sheet
All JavaScript array methods at a glance — iteration, transformation, search, mutation, and ES2022+ additions.
Iteration
| Method | Returns | Description |
|---|---|---|
| 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) |
Search & Check
| Method | Returns | Description |
|---|---|---|
| arr.find(fn) | element|undefined | First element where fn returns true |
| arr.findIndex(fn) | number | Index of first match, -1 if none |
| arr.findLast(fn) | element|undefined | Last element matching fn (ES2023) |
| arr.indexOf(val) | number | First index of val using ===, -1 if not found |
| arr.lastIndexOf(val) | number | Last index of val, -1 if not found |
| arr.includes(val) | boolean | True if val is in array (handles NaN) |
| Array.isArray(val) | boolean | True if val is an array |
Mutation (modifies original)
| Method | Returns | Description |
|---|---|---|
| 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)
| Method | Returns | Description |
|---|---|---|
| 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) |