check if two vectors have values in common js 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: check if 2 arrays are equal javascript
var arraysMatch = function (arr1, arr2) {
if (arr1.length !== arr2.length) return false;
for (var i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) return false;
}
return true;
};