Skip to content
Advertisement

filtering data with array of objects data es6

I am trying to filter array of objects with another array of objects.

var actualData = [{modifiedy: "USER", createdOn: "2021-03-18", id: 33 },{modifiedy: "USER", createdOn:"2021-03-18", id: 22},{modifiedy: "USER", createdOn: "2021-03-18", id: 36},  {modifiedy: "USER", createdOn: "2021-03-18", id: 11 }] 

var selectedItems = [33,22]

I need to return Items which are not include in actual Data.

I have tried using below function but I am getting undefined “some” error.

 const filtered = result.filter((p) => !p.checkedItems.some((a) => checkedItems.includes(a.id)));

I have searched a lot achieve my requirement but I didn’t any solution can some one help me to fix this issue.

Advertisement

Answer

Try this

 var filtered = actualData.filter(function (item) {
        return selectedItems.indexOf(item.id) === -1;
    });
    console.log('filtered', filtered);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement