Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find difference between two array using lodash/underscore in nodejs

People also ask

How do you find the difference between two arrays in Lodash?

1 - lodash differenceThe lodash distance method can be used to find the difference between two arrays. Just give an array as the first argument, and another as the second, and what will be returned is a new array of values that are not in second array when comparing element by element.


Use _.differenceWith, and pass a comparator which compares two arrays, as in:

_.differenceWith(a, b, _.isEqual);

As mentioned by @dsl101,

_.xor([1, 2, 3], [2, 3, 4]);
// [1, 4]