Nacim Idjakirene Nacim Idjakirene - 18 days ago 7
Javascript Question

Lodash / javascript : Compare two collections and return the differences

I have two array of object :

the element of my table are not primitive value, but complexe objects.

array1 = [obj1,obj2,obj3,obj4]
array2 = [obj5,obj5,obj6,obj7]


I would like to compare two arrays and see of the elements of array 2 are already present in array1 then create a new array of the difference.

Any suggestion ?

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