Consider below two arrays of objects:
const arr1 = [
{name: "name1", id: 1},
{name: "name2", id: 2},
{name: "name3", id: 3}
];
const arr2 = [
{name: "name1", id: 1},
{name: "name2", id: 4},
{name: "name3", id: 3}
];
Comparison of these two objects must return false because there are values for prop id in arr2 that are missing in arr1 (namely id: 4).
At this point, the below attempt has been made:
arr1.every(i => i.id === arr2.map(z =>z.id));
NOTE:
Suppose arr2 was:
const arr2 = [
{name: "name1", id: 1},
{name: "name3", id: 3}
];
The comparison must return true, since the id of every element in arr2 is found in arr1's elements.
arr1.every(i => arr2.map(z => z.id).includes(i.id))<--- please try this & share feedback.