This JavaScript array methods cheat sheet lists the most-used array methods for adding, removing, transforming and searching elements.
Add / remove
| Method | What it does |
|---|---|
| push(x) | Add to the end |
| pop() | Remove from the end |
| unshift(x) | Add to the start |
| shift() | Remove from the start |
| splice(i, n) | Remove/insert at index |
| slice(a, b) | Copy a section |
Transform / search
| Method | What it does |
|---|---|
| map(fn) | Transform each item |
| filter(fn) | Keep items that match |
| reduce(fn, init) | Reduce to one value |
| forEach(fn) | Loop over items |
| find(fn) | First matching item |
| findIndex(fn) | Index of first match |
| includes(x) | Does it contain x? |
| indexOf(x) | Index of x |
| some(fn) | Any match? |
| every(fn) | All match? |
| sort(fn) | Sort in place |
| reverse() | Reverse in place |
| concat(arr) | Join arrays |
| join(sep) | Array to string |
| flat() | Flatten nested arrays |