问题描述var obj ={ apple: 1, banana:2, li:30};var arr = [
{id:'1',text:'苹果',key:'apple', value:''},
{id:'2',text:'梨', key:'li',value:''},
{id:'3',text:'香蕉', key:'banana', value:''}
];// 结果:生成一个新的数组var newArr = [
{id:'1',text:'苹果',key:'apple', value:'1'},
{id:'2',text:'梨', key:'li',value:'2'},
{id:'3',text:'香蕉', key:'banana', value:'30'}
];如何实现?
2 回答
慕沐林林
TA贡献2016条经验 获得超9个赞
var newArr = arr.map(item=>{ let newObj = JSON.parse(JSON.stringify(item)) let value = obj[ newObj[key] ] newObj.value = value ? value : '' return newObj })
ibeautiful
TA贡献1993条经验 获得超5个赞
var data = arr.map(function (item) {
item.value = obj[item.key];return item
});
添加回答
举报
0/150
提交
取消