Nacim Idjakirene Nacim Idjakirene - 1 year ago 164
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 Source
var presents = _.intersectionWith(array1, array2, _.isEqual);
var dif = _.differenceWith(array1, array2, _.isEqual);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download