数组a
var a = [{key:1,name:'name1'},{key:2,name:'name2'},{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'}];
当数组b为 var b = [{key:1,name:'name1'}];
,最后的结果应该是[{key:2,name:'name2'},{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'}]
当数组b为var b = [{key:3,name:'name3'},{key:4,name:'name4'}];
,最后的结果应该是[{key:1,name:'name1'},{key:2,name:'name2'},{key:5,name:'name5'}]
也就是想得到数组a-数组b的结果。
使用difference只对数组有效,对里面是对象并没有效
var a2 = [1,2,3,4,5];
var b2 = [1,5];
console.log(_.difference(a2,b2))