After some trying I could find a solution that looks pretty nice like that:
const b = Object.assign({}, a, {
user: {
...a.user,
groups: 'some changed value'
}
});
To make that answer more complete here a tiny note:
const b = Object.assign({}, a)
is essentially the same as:
const b = { ...a }
since it just copies all the properties of a
(...a
) to a new Object. So the above can written as:
const b = {
...a, //copy everything from a
user: { //override the user property
...a.user, //same sane: copy the everything from a.user
groups: 'some changes value' //override a.user.group
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…