This should work:
foodArray.filter(obj =>
filterArray.every(e => !!obj[e.key].find(unit => unit.id === e.id)),
);
General idea: check every object in foodArray
. Then check if every element from filterArray
is found in the array by key
.
Take a look at:
Array.filter
Array.every
Array.find
solved How can I filter an array of objects by data from another array of objects? [closed]