constarr1=['1','2','3','5']constarr2=[{id:'1',},{id:'2',},{id:'3',},{id:'4',}]需求就是arr1跟arr2比较如果arr2得ID等于arr1得话就把等于得arr2放到新数组中如果有不等于的话把arr1不等于arr2得值放到一个新数组中结果就是要相等数组:是arr2id[{id:'1'},{id:'2'},{id:'3'}]不相等数组:是arr1[5]
2 回答
沧海一幻觉
TA贡献1824条经验 获得超5个赞
var array1 = [ {"Num": "A " },{"Num": "B" }];var array2 = [ {"Num": "A ","Name": "t1 " }, {"Num": "B","Name": "t2"}, {"Num": "C " ,"Name": "t3 "}];var result = [];for(var i = 0; i < array2.length; i++){ var obj = array2[i]; var num = obj.Num; var isExist = false; for(var j = 0; j < array1.length; j++){ var aj = array1[j]; var n = aj.Num; if(n == num){ isExist = true; break; } } if(!isExist){ result.push(obj); }}console.log(result);
添加回答
举报
0/150
提交
取消