JavaScript arrays come with a rich set of built-in methods for transforming, searching, and reordering data. This cheat sheet groups the essential array methods by task — transforming, searching, adding and removing, ordering, iterating, and creating — so you can pick the right one at a glance.
For each method you'll see the call signature and a short note on what it returns and whether it changes the original array. Working with JSON or formatting output? Try the <a href="/tools/javascript-beautifier">JavaScript Beautifier</a>.
Transforming
| Method | What it does |
|---|
map(fn) | Create a new array by transforming each element. |
filter(fn) | Create a new array with only the elements that pass a test. |
reduce(fn, init) | Reduce the array to a single accumulated value. |
reduceRight(fn, init) | Like reduce, but iterates right to left. |
flat(depth) | Flatten nested arrays up to the given depth. |
flatMap(fn) | Map each element, then flatten the result one level. |
Searching & Testing
| Method | What it does |
|---|
find(fn) | Return the first element that passes a test. |
findIndex(fn) | Return the index of the first matching element, or -1. |
findLast(fn) | Return the last element that passes a test. |
indexOf(value) | Return the first index of a value, or -1 if absent. |
includes(value) | Return true if the array contains a value. |
some(fn) | Return true if at least one element passes a test. |
every(fn) | Return true only if every element passes a test. |
Adding & Removing
| Method | What it does |
|---|
push(item) | Add an item to the end; returns the new length. |
pop() | Remove and return the last item. |
unshift(item) | Add an item to the start; returns the new length. |
shift() | Remove and return the first item. |
splice(start, count, ...items) | Add or remove items in place at any index. |
slice(start, end) | Copy a portion into a new array (non-mutating). |
concat(arr) | Merge one or more arrays into a new array. |
Ordering
| Method | What it does |
|---|
sort(fn) | Sort in place; pass a comparator for numeric order. |
reverse() | Reverse the order of elements in place. |
toSorted(fn) | Return a sorted copy without mutating the original. |
toReversed() | Return a reversed copy without mutating the original. |
Iterating
| Method | What it does |
|---|
forEach(fn) | Run a function once for each element (no return value). |
entries() | Return an iterator of [index, value] pairs. |
keys() | Return an iterator of the array's indices. |
values() | Return an iterator of the array's values. |
Creating & Joining
| Method | What it does |
|---|
Array.from(iterable) | Create an array from an iterable or array-like value. |
Array.of(1, 2, 3) | Create an array from the given arguments. |
Array.isArray(x) | Return true if a value is an array. |
join(separator) | Join all elements into a single string. |
fill(value) | Fill all elements with a static value in place. |
JavaScript Array Methods Cheat Sheet FAQs
What is the difference between map and forEach?
map returns a new array built from the value you return for each element, so it is used to transform data. forEach returns nothing — it is used only for side effects like logging. If you need a result, reach for map.
What is the difference between filter and find?
filter returns a new array of every element that passes the test. find returns only the first matching element (or undefined). Use filter when you want all matches, find when you want just one.
How does reduce work in JavaScript?
reduce(fn, init) walks the array while carrying an accumulator. On each step it runs fn(accumulator, currentValue) and the return value becomes the next accumulator. It is used to collapse an array into a single value, such as a sum or a grouped object.
Which array methods mutate the original array?
push, pop, shift, unshift, splice, sort, reverse, and fill change the array in place. Methods like map, filter, slice, and concat return a new array and leave the original unchanged.
What is the difference between slice and splice?
slice(start, end) returns a copy of a portion of the array without changing it. splice(start, count, ...items) removes or inserts elements in place and mutates the original array. The names are similar but their behavior is very different.
How do I sort an array of numbers correctly?
Pass a comparator: arr.sort((a, b) => a - b) for ascending order. Without a comparator, sort converts values to strings, so [10, 2, 1] would sort as [1, 10, 2]. Use toSorted to sort without mutating the original.
What is the difference between some and every?
some(fn) returns true if at least one element passes the test. every(fn) returns true only if all elements pass. Both stop early as soon as the answer is known, which makes them efficient for checks.