Rumah > Soal Jawab > teks badan
Susun a
var a = [{key:1,name:'name1'},{key:2,name:'name2'},{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'}];
Apabila array b ialah var b = [{key:1,name:'name1'}];
,最后的结果应该是[{key:2,name:'name2'},{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'}]
Apabila array b ialah var b = [{key:3,name:'name3'},{key:4,name:'name4'}];
,最后的结果应该是[{key:1,name:'name1'},{key:2,name:'name2'},{key:5,name:'name5'}]
Iaitu, saya ingin mendapatkan hasil array a-array b.
Menggunakan perbezaan hanya berkesan untuk tatasusunan, bukan untuk objek di dalam
var a2 = [1,2,3,4,5];
var b2 = [1,5];
console.log(_.difference(a2,b2))