Array.prototype.splice and a schoolboy error.
In a previous post, I discussed the lack of a direct method in JavaScript for deleting arbitrary elements from an array. I had attempted a solution, but misread the documentation for Array.prototype.splice
. While I believe my solution is still useful for removing elements without needing to find their indices first, splice
does allow removing arbitrary elements by index. To remove one element at a specific position, use values.splice(index, 1)
. This modifies the original array and returns an array of the removed elements. Thanks to @dezfowler for pointing this out!