Skip to content
Advertisement

Get Values of nested Objects in Loop

I have the following goal. An array of strings that I can use to get the keys of an object that I need. My problem is, I don’t know how to get to the nested properties in my loop.

My array:

JavaScript

My object:

JavaScript

My loop:

JavaScript

Of course, all nested properties don’t work. But how can I access them within a loop? I tried it with arr[i].split(".") but don’t know, how I can put an array of keys to get the properties. This works but isn’t good for deeply nested properties.

JavaScript

I probably have the wrong approach, but can’t come up with the right answer.

Advertisement

Answer

Here is a solution for you

JavaScript

Here is usage

JavaScript

Here is result

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