JS Array Methods Table
| Method | Returns | What it does |
|---|---|---|
| map() | newArray | Transforms every element using the callback |
| filter() | newArray | Keeps elements where the callback returns true |
| reduce() | single value | Accumulates elements into one value |
| find() | element or undefined | First element matching the condition |
| findIndex() | number or -1 | Index of first element matching the condition |
| some() | boolean | True if at least one element passes the test |
| every() | boolean | True if all elements pass the test |
| includes() | boolean | True if the array contains the value |
| sort() | same array (mutates) | Sorts in place - always pass a comparator for numbers |
| flat() | newArray | Flattens nested arrays one level (or depth argument) |
| flatMap() | newArray | map() then flat() in one pass |
| join() | string | Concatenates all elements with a separator |
JavaScript arrays have 30+ methods, but twelve cover virtually all array work: map (transform each), filter (keep matching), reduce (accumulate to one value), find (first match), findIndex (position of first match), some (at least one passes), every (all pass), includes (contains), sort (order in place), flat (flatten nested), flatMap (map+flatten) and join (to string).
The mutation distinction is the most common source of bugs: sort() modifies the original array while map() and filter() return new ones. In modern JS, toSorted() gives you a sorted copy without mutation.
How to use
- Filter by method name or what it returns - new array, single value, mutates - to find the tool you need.
- Click any method to copy the name into your code or documentation.
- Read the returns column: it tells you whether the original array is preserved.
Frequently asked questions
Why does sort() sort numbers incorrectly by default?
sort() without a comparator converts elements to strings and compares them lexicographically: [10, 1, 5] becomes [1, 10, 5] because "10" sorts before "5" as strings. Always pass a comparator for numbers: arr.sort((a, b) => a - b) for ascending.
What is the difference between splice and slice?
splice() modifies the original array - it removes, replaces or inserts elements in place. slice() returns a new array without modifying the original. The one-letter difference between p and l (splice vs slice) is the difference between mutation and immutability.
When should I use flatMap instead of map + flat?
Use flatMap when your callback returns an array for each element and you want to flatten the result in one pass. It is equivalent to arr.map(fn).flat() but avoids creating an intermediate array. The classic use case: splitting sentences into words, or expanding one-to-many relationships.
Does reduce() have a use case beyond summing numbers?
Yes - reduce is the most powerful array method because it can implement map, filter, find, group by, count by, and any other transformation. It is the functional programming building block: everything else is a specialised version of reduce. But use the specialised methods first for readability.