Last updated: April 12, 2026
JavaScript Array Methods Cheatsheet
Quick Answer
JavaScript arrays have powerful built-in methods. Use map() to transform, filter() to select, reduce() to aggregate, find() to search, and sort() to order. This cheatsheet covers 25 essential array methods with examples.
Transform
| Command | Description |
|---|---|
| arr.map(fn) | Create a new array by transforming each element [1,2,3].map(x => x * 2) // [2,4,6] |
| arr.filter(fn) | Create a new array with elements that pass the test [1,2,3,4].filter(x => x > 2) // [3,4] |
| arr.reduce(fn, init) | Reduce array to a single value [1,2,3].reduce((sum, x) => sum + x, 0) // 6 |
| arr.flat(depth) | Flatten nested arrays to the specified depth [[1,2],[3,[4]]].flat(2) // [1,2,3,4] |
| arr.flatMap(fn) | Map then flatten one level (more efficient than map+flat) ["hi bye"].flatMap(s => s.split(" ")) // ["hi","bye"] |
Search
| Command | Description |
|---|---|
| arr.find(fn) | Return the first element that matches [1,2,3].find(x => x > 1) // 2 |
| arr.findIndex(fn) | Return index of the first matching element (-1 if none) [1,2,3].findIndex(x => x > 1) // 1 |
| arr.includes(val) | Check if array contains a value (boolean) [1,2,3].includes(2) // true |
| arr.indexOf(val) | Return first index of a value (-1 if not found) ["a","b","c"].indexOf("b") // 1 |
| arr.some(fn) | Test if at least one element passes [1,2,3].some(x => x > 2) // true |
| arr.every(fn) | Test if all elements pass [1,2,3].every(x => x > 0) // true |
Order
| Command | Description |
|---|---|
| arr.sort(fn) | Sort array in place (mutates!) [3,1,2].sort((a,b) => a - b) // [1,2,3] |
| arr.reverse() | Reverse array in place (mutates!) [1,2,3].reverse() // [3,2,1] |
| arr.toSorted(fn) | Return new sorted array (non-mutating, ES2023) [3,1,2].toSorted((a,b) => a-b) // [1,2,3] |
| arr.toReversed() | Return new reversed array (non-mutating, ES2023) |
Add/Remove
| Command | Description |
|---|---|
| arr.push(val) | Add element(s) to the end (mutates, returns new length) [1,2].push(3) // arr is [1,2,3] |
| arr.pop() | Remove and return the last element (mutates) [1,2,3].pop() // returns 3 |
| arr.unshift(val) | Add element(s) to the beginning (mutates) |
| arr.shift() | Remove and return the first element (mutates) |
| arr.splice(start, count, ...items) | Remove/replace/add elements at an index (mutates) [1,2,3].splice(1, 1, "a") // [1,"a",3] |
| arr.slice(start, end) | Return a shallow copy of a portion (non-mutating) [1,2,3,4].slice(1, 3) // [2,3] |
Combine
| Command | Description |
|---|---|
| arr.concat(arr2) | Merge arrays (returns new array) [1,2].concat([3,4]) // [1,2,3,4] |
| [...arr1, ...arr2] | Spread to merge arrays (same as concat) [...[1,2], ...[3,4]] // [1,2,3,4] |
| arr.join(sep) | Join elements into a string ["a","b","c"].join("-") // "a-b-c" |
Create
| Command | Description |
|---|---|
| Array.from(iterable) | Create an array from an iterable or array-like Array.from({length: 3}, (_, i) => i) // [0,1,2] |
Frequently Asked Questions
More Cheatsheets
Git Commands Cheatsheet
This cheatsheet covers the 40 most essential Git commands grouped by workflow: setup, staging, branc...
Docker Commands Cheatsheet
This cheatsheet covers 35 essential Docker commands for managing containers, images, volumes, and ne...
Linux Commands Cheatsheet
This cheatsheet covers 40 essential Linux/Unix commands for daily development: file navigation, text...
HTTP Status Codes Cheatsheet
HTTP status codes are 3-digit numbers returned by servers. 1xx = informational, 2xx = success, 3xx =...