2👍
✅
Spread foo
into its own object with a c
property with a value of an object. Then spread foo.c
into this object, which you can add the title
property to like so:
foo2: {...foo, c: {...foo.c, 'title':'Copy'}
Spreading foo.c
will allow any additional own enumerable properties (if any) from foo.c
to remain in the new c
object value.
0👍
Will it work?
const foo = {a: 'A', b: 'B', c: {title: "Main"}}
const foo2 = { ...foo, c: { ...foo.c, title: 'Copy' } }
console.log(foo2)
Source:stackexchange.com