I'm trying to get all the key names 2 levels into an object (potentially further in in the future).
For example given an object like:
myThing = {
'someKeyTopLevel1': {
'someKeySecondLevel1': [
... very large data here ...
],
'someKeySecondLevel5': [
... very large data here ...
]
},
'someKeyTopLevel2': {
'someKeySecondLevel1': [
... very large data here ...
],
'someKeySecondLevel2': [
... very large data here ...
],
'someKeySecondLevel3': [
... very large data here ...
]
}
...
}
The desired result would be an array of 'someKeySecondLevel1', 'someKeySecondLevel2', 3, 5, etc.
I was thinking of doing something like (pseudo-code):
- Grab all keys from top level (
Object.keys(myThing)
) - Iterate through those keys and get the entries, get the keys within those entries using
Object.keys(...)
again.
Is there a more standard / faster / better way to do this?
I'm worried that since our dataset is actually pretty big, it might not perform very well, especially if eventually we had to do the same thing for something, say three levels down or more.
Any help would would be appreciated!