var arr=[
{id:1,name:'11'},
{id:2,name:'11'},
]
var brr =[
{id:1,type:'11'},
{id:2,type:'11'}
]
function concatArr(arr,brr){
var newArr =arr.concat(brr);
var has ={},res=[];
for(let i = 0 ;i<newArr.length;i++){
var item= newArr[i];
console.log(item);
if(!has[item.id]){
res.push({
...item
})
has[item.id] = item;
}else{
for(let j=0;j<res.length;j++){
var se= res[j];
if(se.id == item.id){
res[j] ={...se,...item}
break
}
}
}
}
return res;
}
复制代码
转载于:https://juejin.im/post/5b8f89835188255c520cedaa