Object.assign—override nested property

前端 未结 7 448
轮回少年
轮回少年 2020-12-13 01:36

I have an Object a like that:

const a = {
  user: {
   …
   groups: […]
   …
  }
}

whereby there are a lot more properties in

相关标签:
7条回答
  • 2020-12-13 02:28

    You can change it this way,

    const b = Object.assign({}, a, {
      user: Object.assign({}, a.user, {
              groups: {}
            })
    });
    
    0 讨论(0)
提交回复
热议问题