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]; } } } } console.log(arr2);
arr1拼接到arr2中