how to delete selected objects from array by key value. javascript
//main array list
arrayList = [{'id':1,'name':'salman',age:'22'},{'id':2,'name':'Adam',age:'21'},{'id':3,'name':'John',age:'23'}];
//list of object ids to be deleted
idList [id:1,id:3];
//delete method
idList.forEach(f => arrayList.splice(arrayList.findIndex(e => e.id === f.id),1));
console.log(arrayList);
----Output----
[{'id':2,'name':'Adam',age:'21'}];
Comments
Post a Comment