This is an issue that cropped up for me today: I was splicing a name out of an array and was getting the wrong result back. The issue was a simple ...
For further actions, you may consider blocking this person and/or reporting abuse
Array in-place mutation gets really annoying at times for this very reason.
Many array methods are a toss up between returning a new array and mutating the old one.
Here is a quick list of array methods that mutate in place. All other array methods do not.
When dealing with removing an item from the array, I generally like to do an immutable version for the reason described above in the post. So instead of
I would use
Excellent information ... now to retrain an old brain to remember the .filter ... Thanks!
When I get issues like this, the first thing I do is go to MDN and check what's the return value of the mehtod Im using is (or if there's any at all) :)
Yeah ... I should be thinking that route. I struggled with finding a good set of search terms to describe my issue. This method usually works extremely well for me.
I'll definitely keep your idea in mind for the next time I get bogged down like this!
Thanks!
You could use
slice
instead too.Absolutely ... this was just the issue I had at the time.