js比较两个数组对象,取出不同的值
vararray1="object":[{"Num":"A"},{"Num":"B"}];========================================...
var array1= "object": [ {"Num": "A " },{"Num": "B" }];
========================================================
var array2= "object": [ {"Num": "A ","Name": "t1 " }, {"Num": "B","Name": "t2"}, {"Num": "C " ,"Name": "t3 "}];
我想比较这两个数组的Num,取出array2数组不包括array1的数据,想得出结果如下:
该怎么做
var result= "object": [ {"Num": "C " ,"Name": "t3 "}]; 展开
========================================================
var array2= "object": [ {"Num": "A ","Name": "t1 " }, {"Num": "B","Name": "t2"}, {"Num": "C " ,"Name": "t3 "}];
我想比较这两个数组的Num,取出array2数组不包括array1的数据,想得出结果如下:
该怎么做
var result= "object": [ {"Num": "C " ,"Name": "t3 "}]; 展开
2个回答
展开全部
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);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询