这样两个对象如何合并成obj3的格式???求指教
1 回答
心有法竹
TA贡献1866条经验 获得超5个赞
const obj1 = {"name":"","age":"","salary":""};
const obj2 = [
{"desc":"年龄",content:"25"},
{"desc":"薪资",content:"3000"},
{"desc":"姓名",content:"李杰"}
];
//汉英字典映射
const dict = {
"年龄":"age",
"薪资":"salary",
"姓名":"name"
}
const obj3 = {...obj1};
obj2.forEach(item=>{
if(item.desc in dict){
const key = dict[item.desc];
const value = item.content;
obj3[key] = value;
}
});
console.log(obj3);
添加回答
举报
0/150
提交
取消