remove object from array javascript by id code example
Example 1: remove item from array by id
var myArr = [{id:'a'},{id:'myid'},{id:'c'}];
var index = arr.findIndex(function(o){
return o.id === 'myid';
})
if (index !== -1) myArr.splice(index, 1);
Example 2: object delete with id filter javascript
const hero = [{'id' : 1, 'name' : 'hero1'}, {'id': 2, 'name' : 'hero2'}];
const updatedHero = hero.filter(item => item.id !== 1);
Example 3: remove id from array javascript
const drinks = ['Cola', 'Lemonade', 'Coffee', 'Water'];
const id = 2;
const removedDrink = drinks.splice(id, 1);