Skip to content
Advertisement

how to insert deep in object

I have this object with tables:

JavaScript

An I would like to insert dynamicly a new table. I tried this:

JavaScript

But it overwrites my exsiting entrances.

This will also not work:

JavaScript

How this will work?

JavaScript

Advertisement

Answer

For a more reusable solution, take a look at this SO question – you want to deep merge the new object with the old one, not shallowly merge them.

A non reusable solution can be built like this (to illustrate that for more complex paths/requirements the above solution is much easier):

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement