Which JavaScript Array functions are mutating?

JavascriptArraysMutable

Javascript Problem Overview


I am writing an Array-derived class in JavaScript and need to know which functions to overload so that I can be aware of changes made to the array.

I know Array.push() and Array.splice() are mutating. Is there a definitive list of any others?

Javascript Solutions


Solution 1 - Javascript

You can find the list on MDN as Mutator methods (along with Accessor and Iteration methods):

Solution 2 - Javascript

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(...)

Solution 3 - Javascript

I found this website called Doesitmutate

Have the list of all functions - and tells whether it mutates or not.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondevios1View Question on Stackoverflow
Solution 1 - JavascriptJonathan LonowskiView Answer on Stackoverflow
Solution 2 - JavascriptVinnie JamesView Answer on Stackoverflow
Solution 3 - JavascriptSoorajView Answer on Stackoverflow