I have two arrays with the following structures:
const array1 = [{id: 1, name: "test"}, {id: 2, name: "test2"}, {id: 3, name: "test3"}];
const array2 = [{weight: 1, ids: [1]}, {weight 3, ids: [3]}];
I want to filter array1 so that it only has items where the id does not exists within any of the ids arrays within array 2.
I tried the following:
array1.filter((item) =>
!array1?.filter((item2) =>
item2?.ids?.includes(item.id)
)
)
however it just returns an empty array.
Can anyone provide me with the correct way of doing this filtering?