Just wanting to say that all JS solutions are quite 'bad', except the simple for-of, because they're combining pure array methods (.map, .reduce) and side-effects (external variable to that method), not even talking about modifying Array protoype https://github.com/josevalim/nested-data-structure-traversal..., never do this, don't touch to objects you don't own, and that others would access and not expect to be modified!
I'll make a PR to try to contribute, instead of just complaining like that, hehe
Btw I'm surprised the structure isn't deeply nested (requiring recursion to process it), it'd be more interesting