Skip to content
Advertisement

Find and remove objects in an array based on a key value in JavaScript

I have been trying several approaches on how to find an object in an array, where ID = var, and if found, remove the object from the array and return the new array of objects.

Data:

JavaScript

I’m able to search the array using jQuery $grep;

JavaScript

But how can I delete the entire object when id == 88, and return data like the following?

Data:

JavaScript

Advertisement

Answer

I can grep the array for the id, but how can I delete the entire object where id == 88

Simply filter by the opposite predicate:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement