Which JavaScript Array functions are mutating?
You can find the list on MDN as Mutator methods (along with Accessor and Iteration methods):
copyWithin
fill
pop
push
reverse
shift
sort
splice
unshift
You can also use .concat()
, before using your mutation method, to ensure you are not mutating your arrays, eg
const dontMutateMe = [4,5,1,2,3];
const sortArray = dontMutateMe.concat().sort(...)