let arr1= [{name:'zhangsan',age:14},{name:'lisi',age:18}] //这是后台返回的数据
let arr2= [{name:'张三',zname:'zhangsan'},{name:李四,zname:lisi}] //后代返回的对照表
变成
[{name:zhangsan,age:14,title:'张三'},{name:'lisi',age:18,title:'李四'}]
let arr1= [{name:'zhangsan',age:14},{name:'lisi',age:18}] //这是后台返回的数据
let arr2= [{name:'张三',zname:'zhangsan'},{name:李四,zname:lisi}] //后代返回的对照表
变成
[{name:zhangsan,age:14,title:'张三'},{name:'lisi',age:18,title:'李四'}]
你题目的解答代码如下:(如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮)
let arr1= [{name:'zhangsan',age:14},{name:'lisi',age:18}] //这是后台返回的数据
let arr2= [{name:'张三',zname:'zhangsan'},{name:'李四',zname:'lisi'}] //后代返回的对照表
let obj = {};
arr2.forEach(function(v, i){
obj[v.zname] = v;
});
arr1.forEach(function(v, i){
v.title = obj[v.name].name;
});
console.log(arr1);