consider this two array of objects :
const arr1 = [
{id: 'parent1', title: 'product1', childProducts: [{id: 'child1', title: 'childProduct1'}]},
{id: 'parent2', title: 'product2', childProducts: [{id: 'child2', title: 'childProduct2'}]},
];
const arr2 = [{id: 'child1', title: 'childProduct1'}];
I need to compare childProducts
of arr 1 with arr 2 and somehow filter arr 1 like below:
const result = [{id: 'parent2', title: 'product2', childProducts: [{id: 'child2', title: 'childProduct2'}]}]
in other words, I need to return elements from arr1 that their childProducts
are not in arr2 (whith help of loops).
how can I achieve this?