MK01111000
MK01111000

Reputation: 832

How do I push an object into an array nested in an object and retain reactivity in Vue

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.assignbut that does not work in this case because of the array.

Upvotes: 0

Views: 232

Answers (1)

Shirish Maharjan
Shirish Maharjan

Reputation: 502

try this

obj.property3.push({ property7: 'value7'})
obj={...obj}

Upvotes: 1

Related Questions