The lodash _.remove array method and vanilla javaScript alternatives
The process of removing a few elements from an array can sometimes be a little troubling, or at least I remember that it was back when I was first starting out with javaScript. The trouble was mainly with looping over an array from a zero element index value upwards, each time an element is removed it of course changes the length of an array, which of course causes a problem when looping forward threw array index values that way. One way that I would resolve the problem is by looping threw the array backwards, and using an array prototype method like Array.splice to purge elements out. For the most part that seems to work okay, but here is a wide range of other ways to go about doing this sort of thing.
So when it comes to just using native javaScript alone of course there are ways of just going ahead and removing elements from an array. However this is a post on lodash where it is assumed that lodash is part of the stack of a project, so with that said there is also the _.remove array method to work with. It works by passing a method that is used to define the conditions that are to be used to remove one or more elements from an array, and on top of that will mutate the array in place just like that of the array splice method. However unlike the array splice method I can define a condition by which to remove all elements that meet the condition, rather than a start index and count of elements.
There are however other methods of interest, both in lodash and native javaScript though such as the filter method that might be a better option as it will do the same only not mutate the array in place. Still lots of developers are transitioning away from lodash, so I will also be looking at some vanilla js alternatives such as array splice, but also other native methods. Also there are some additional related topics that come to mind such as the question of removing elements at all to begin with or not when it comes to the idea of just having a fixed set of elements that are simply reused rather than created and purged, such is the case with an object pool.