Skip to content
Advertisement

Separating (n) keys from array of objects into a single array with keys names

I need to perform filter in the array of objects to get all the keys. Although, whenever there is a obj inside of that key, I would need to get the key name and concat with the key name from the obj, so for example:

JavaScript

I could manage to do the above code, but, if there is more objs inside the data, I would need to keep adding a if condition inside of my logic, I would like to know if there is any other way, so it doesn’t matter how many objects I have inside the objects, It will concat always.
The code I used from the above mention:

JavaScript

What I would like to achieve, lets suppose I have this array of object:

JavaScript

I would like to achieve, all the keys from the first object of the array, and if there is objects inside of objects, I would like to concat the obj names (obj.obj2key1)

Advertisement

Answer

You could map the key or the keys of the nested objects.

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