Filter array of objects by array of ids

You can simply use array.filter with indexOf to check the matching element in the next array.

var arr = serviceList.filter(item => activeIds.indexOf(item.id) === -1);

DEMO

let activeIds = [202, 204]
let serviceList = [{  
                "id":201,
                "title":"a"
               },
               {  
                "id":202,
                "title":"a"
               },
               {  
                "id":203,
                "title":"c"
               },
               {  
                "id":204,
                "title":"d"
               },
               {  
                "id":205,
                "title":"e"
               }];


let  arr = serviceList.filter(function(item){
      return activeIds.indexOf(item.id) === -1;
    });
    
console.log(arr);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)