Reputation: 832
I have the following object:
{ property1:'value1', property2:'value2', property3:[{ property4:'value4' },{ property5: 'value5'}], property6:'value6' }
And now I want to push the following into the value of property3
{ property7:‘value7’}
The final result would be like
{ property1:'value1', property2:'value2', property3:[{ property4:'value4' },{ property5: 'value5'},{property7:'value7'}], property6:'value6'}
Any idea how to do this?
I tried Object.assign
but that does not work in this case because of the array.
Upvotes: 0
Views: 232
Reputation: 502
try this
obj.property3.push({ property7: 'value7'})
obj={...obj}
Upvotes: 1