两个Object根据key赋值合并(Object.keys)
2021-09-24 本文已影响0人
前端小飞象
let obj1={
name:'111',
age:20,
sex:1
}
let obj2={
name:'222',
age:45
}
Object.keys(obj1).forEach(i=>{
if(obj2[i]){
obj1[i]=obj2[i]
}
})
console.log(obj1)//{name: "222", age: 45, sex: 1}