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

Popular posts from this blog

how to save images with angular nodejs

How to add splash screen and app icon with ionic capacitor angular android app