let localData = {
name: '',
sex: ''
}
let resData = {
name: 'zzs',
sex: 'boy',
age: 18,
birthday: '10-21',
address: 'demo'
}
localData = resData
// { name: 'zzs',
// sex: 'boy',
// age: 18,
// birthday: '10-21',
// address: 'demo' }
console.log(localData)
我希望得到的结果是{
名称:“ zzs”,
性别:“男孩”
}
我不想通过以下方式进行操作。
localData.name = resData.name;
localData.sex = resData.sex;
有没有可以实现的良好性能方法?
谢谢
最佳答案
您可以执行以下操作:
let {name,sex} = resData; //Destructure only values required
localData = {name,sex} // assign to localdata
console.log(localData) //{name: "zzs", sex: "boy"}
关于javascript - 前端如何处理后端返回数据中的冗余字段问题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58624484/