js两个list根据key合并let arr2 = [
{
"id": "101",
"rightname": "ruguo",
'a': '123',
"b": '466',
"c": '789',
}, {
"id": "102",
"rightname": "hello",
},
{
"id": "103",
"rightname": "noshi"
}
]
let arr1 = [
{
"id": "101",
"path": "/a",
"icon": 'icon-add',
}, {
"id": "102",
"path": "/b",
"icon": 'icon-edioter',
},
{
"id": "103",
"path": "/c",
"icon": 'icon-edioter',
}
]
for (var i = 0; i < arr2.length; i++) {
var aa = arr2[i];
var aid = aa.id
for(var w = 0; w < arr1.length; w++){
var bb = arr1[w]
var bid = bb.id;
if(bid == aid){ //id相同开始合并
//迭代arr1⾥⾯的json对象
for(var e in bb){
if(e == 'id') continue;
aa[e] = bb[e];
}
}
}js合并两个数组
}
console.log(arr2);
arr1拼接到arr2中
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论