Remove objects from array by object property - Javascript Array Operation

Javascript examples for Array Operation:Array of Object

Description

Remove objects from array by object property

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from ww  w  .ja  v  a  2s  .  c om
var listToDelete = ['abc', 'efg'];
var arrayOfObjects = [{id:'abc',name:'oh'}, // delete me
                      {id:'efg',name:'em'}, // delete me
                      {id:'hij',name:'ge'}]; // all that should remain

let result = arrayOfObjects.filter( el => (-1 == listToDelete.indexOf(el.id)) );

console.log(result);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials