Skip to content
Advertisement

Return nested object with recursion – Javascript

I have an object with nested object:

JavaScript

I need to return all key: value of list and I must use recursion. I have tried to push the nested object to the local variable in the function, but it fails in the second iteration because the names are different.

Here is the function:

JavaScript

Is there a way to solve it with recursion?

It should return the value properties. In this case

JavaScript

Advertisement

Answer

You could return an array with the values and get the nested values after a check

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