Skip to content
Advertisement

How to work with identical, deeply nested data?

For example, has the following data:

JavaScript

And for example an array with indexes leading to the required element(but can be any other):

JavaScript

How can you work with an element having this data?

For example, need to change “value” in the element at the specified path in “ids”.

Advertisement

Answer

You could take an array of indices and get the item of the property content by calling the function again for each missing index.

JavaScript

If needed, you could add a guard for a missing index and exit early.

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