數組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))
雷雷