后台返回数据,前端取需要的数据
const obj1 = { name:'',age:'' ,sex:''}
const obj2 = { name:'tom',age:18,sex:'男',jop:'student',address:'china' }
Object.keys(obj2).forEach((key)=>{
if(Object.keys(obj1).includes(key)){
obj1[key] = obj2[key]
}
})
console.log(obj1) // {name: 'tom', age: 18, sex: '男'}