Lodash / javascript : Compare two collections and return the differences

_.difference gives you only the elements that are in the 1st array but not in the second one, nothing about the elements on the array 2 that are not in the array 1.

Is this what you want to achieve?


ES6 This will be enough:

array2.filter(e => !array1.includes(e));

without includes

array2.filter(e=> array1.indexOf(e) < 0);

Plunker for you


var presents = _.intersectionWith(array1, array2, _.isEqual);
var dif = _.differenceWith(array1, array2, _.isEqual);

_.differenceWith is only available since 4.0.0 lodash version