Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save amitkulhari26/2f591c7af781fb8d27da7d9bb2c9e30b to your computer and use it in GitHub Desktop.

Select an option

Save amitkulhari26/2f591c7af781fb8d27da7d9bb2c9e30b to your computer and use it in GitHub Desktop.
// https://stackoverflow.com/questions/21987909/how-to-get-the-difference-between-two-arrays-of-objects-in-javascript
//Find values that are in result1 but not in result2
var uniqueResultOne = result1.filter(function(obj) {
return !result2.some(function(obj2) {
return obj.value == obj2.value;
});
});
//Find values that are in result2 but not in result1
var uniqueResultTwo = result2.filter(function(obj) {
return !result1.some(function(obj2) {
return obj.value == obj2.value;
});
});
//Combine the two arrays of unique entries
var result = uniqueResultOne.concat(uniqueResultTwo)
// using lodash
import differenceBy from 'lodash/differenceBy'
const myDifferences = differenceBy(Result1, Result2, 'value')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment