All Cheat Sheets

JavaScript Array Methods

Quick reference for JS array methods — map, filter, reduce, find, sort, flat, and more.

Transform

map()arr.map(x => x * 2)Create new array by transforming each element
flatMap()arr.flatMap(x => [x, x*2])Map then flatten one level
flat()arr.flat(Infinity)Flatten nested arrays

Filter & Find

filter()arr.filter(x => x > 5)Keep elements passing test
find()arr.find(x => x.id === 1)First element passing test
findIndex()arr.findIndex(x => x > 3)Index of first match
includes()arr.includes(3)Check if value exists
some()arr.some(x => x > 10)Any element passes test?
every()arr.every(x => x > 0)All elements pass test?

Reduce

reduce()arr.reduce((sum, x) => sum + x, 0)Reduce to single value
reduceRight()arr.reduceRight((a, x) => a + x, '')Reduce right-to-left

Add & Remove

push()arr.push(4)Add to end, returns length
pop()arr.pop()Remove from end, returns element
unshift()arr.unshift(0)Add to start
shift()arr.shift()Remove from start
splice()arr.splice(1, 2, 'a')Add/remove at index
concat()arr.concat([4, 5])Merge arrays

Sort & Order

sort()arr.sort((a,b) => a - b)Sort in place
reverse()arr.reverse()Reverse in place
toSorted()arr.toSorted((a,b) => a-b)Sort (immutable, ES2023)
toReversed()arr.toReversed()Reverse (immutable, ES2023)

Iterate

forEach()arr.forEach(x => console.log(x))Execute for each element
entries()[...arr.entries()]Iterator of [index, value]
keys()[...arr.keys()]Iterator of indices
values()[...arr.values()]Iterator of values

Create & Convert

Array.from()Array.from({length:5}, (_,i) => i)Create from iterable
Array.of()Array.of(1, 2, 3)Create from arguments
slice()arr.slice(1, 3)Shallow copy portion
join()arr.join(', ')Join as string
at()arr.at(-1)Element at index (supports negative)

Keep the references coming

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.