两个数组去重合并 js
var arr1=[{deviceCheck: true,robotId: "000001246212"},{deviceCheck: true,robotId: "000001244033"}] var arr2=[{deviceCheck: false,robotId: "000001246212"},{deviceCheck: false,robotId: "000001244044"}] repeat(arr1,arr2) function repeat(arr1,arr2){//两个数组去重合并 let json=arr1.concat(arr2); let newJson = []; for(var i=0;i<json.length;i++){ let flag = true; for(var j=0;j<newJson.length;j++){ if(newJson[j].robotId==json[i].robotId){ flag = false; } } if(flag){ //判断是否重复 newJson.push(json[i]); } } arr1=newJson; return arr1 }