Member-only story
How to remove an object that matches a filter from a JavaScript array using array.splice(index, howMany) method.
4 min readDec 22, 2020
Functions used in this tutorial:
- array.some — check if at least one item exists in array.
- array.findIndex — find index of an object in array of objects.
- array.splice(index, howManyToDelete) — split array at index and remove n-number of items past that point, return an item or list of items that were removed.
Sometimes you need to remove an object from an array that contains properties that match a value (or values.)
This tutorial explores one practical use case for this.
What is a practical use case for removing objects from JavaScript array?
One of those use cases is storing association between user and event. For example, when user “likes” a tweet, we store relationship between user id and tweet id. This entry is stored in Mongo (or any other) database. When user “unlikes”…