compare objects in array based off key value code example
Example 1: javascript compare object arrays keep only entries not in both
var result = result1.filter(function (o1) {
return result2.some(function (o2) {
return o1.id === o2.id;
});
});
let result = result1.filter(o1 => result2.some(o2 => o1.id === o2.id));
let result = result1.filter(o1 => !result2.some(o2 => o1.id === o2.id));
Example 2: how to compare javascript objects
function shallowEqual(object1, object2) {
const keys1 = Object.keys(object1);
const keys2 = Object.keys(object2);
if (keys1.length !== keys2.length) {
return false;
}
for (let key of keys1) {
if (object1[key] !== object2[key]) {
return false;
}
}
return true;
}