Array a
var a = [{key:1,name:'name1'},{key:2,name:'name2'},{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'}];
When array b is var b = [{key:1,name:'name1'}];
, the final result should be [{key:2,name:'name2' },{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'}]
When array b is var b = [{key:3,name:'name3'},{key:4,name:'name4'}];
, the final result should be [{key:1,name:'name1'},{key:2,name:'name2'},{key:5,name:'name5'}]
That is, I want to get the result of array a-array b.
Using difference is only effective for arrays, not for objects inside it
var a2 = [1,2,3,4,5];
var b2 = [1,5];
console.log(_.difference(a2,b2))