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?
filter() , the filter() is among the coolest non-mutating method on the array.
In JavaScript, only objects and arrays are mutable, not primitive values.
Generally not. There are times when treating data as immutable is useful, or even essential (such as when you are updating a Redux store). In those cases, push still isn't a bad idea, you just shouldn't do it to your original array.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With