JS 两个含有部分相同属性的对象如何快速给对应的key赋值

obj1 =
{
                "authList": [ ], 
                "enabled": 1, 
                "id": "b3bae8fcde0d4a50b7fbcbbccf4fe216", 
                "lastLogin": 1564363725773, 
                "lastLoginStr": "2019-07-29", 
                "namePinyin": "chenghua", 
                "namePinyinFirst": "c", 
                "rowLocked": 0, 
                "sex": 2, 
                "userAccount": "chenghua", 
                "userName": "lomo"
  }, 


obj2 ={
                "sex": ‘‘, 
                "userAccount": "", 
                "userName": ""
}

  解决方法

Object.keys(obj2).forEach(key=>{obj2[key]=obj1[key]})

 

文章来自:https://www.cnblogs.com/wang-xx/p/12366695.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3