The Array prototype has many methods, and the difference between one that mutates in place and one that returns a fresh array is a frequent source of bugs. This reference lists each method with its signature, return type, mutability, and the ECMAScript version that added it.
How it works
Each method is classified by what it does to the array:
- Mutating —
push,pop,shift,unshift,splice,sort,reverse,fill,copyWithinchange the array in place. - Non-mutating —
map,filter,slice,concat,flat, and the rest return a new array or a single value, leaving the original untouched. - Immutable copies (ES2023) —
toSorted,toReversed,toSpliced, andwithare drop-in immutable versions of the mutating methods.
The reference tags each entry so you can see at a glance whether calling it is safe inside a pure function or a React render.
Tips
Inside React state updates and any functional pipeline, avoid the mutating
methods on data you do not own — sort a copy with [...arr].sort() or use
toSorted(). Remember reduce needs an initial value to be safe on possibly
empty arrays, and that map/filter/forEach skip holes in sparse arrays.
indexOf uses strict equality so it cannot find NaN; use includes, which
does, when NaN matters.