DD
DevDash

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

CommandDescription
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

CommandDescription
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

CommandDescription
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

CommandDescription
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

CommandDescription
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

CommandDescription
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

Want API access + no ads? Pro coming soon.