I'm trying to transform an object that could have varying levels of nesting:
const obj = {
    some: {
        thing: {
            good: 'yo'
        },
        one: 'else'
    },
    something: {
        bad: 'oy'
    },
    somethingtasty: 'mmm'
}
into an array of objects containing the original path of the value and the value:
const arr = [{
        path: 'some.thing.good',
        value: 'yo'
    }, {
        path: 'some.one',
        value: 'else
    }, {
        path: 'something.bad',
        value: 'oy'
    }, {
        path: 'somethingtasty',
        value: 'mmm'
    }]
I found a helpful answer on SO for a similar question dealing with objects of varying nestedness:
https://stackoverflow.com/a/2631198
But this doesn't solve
- a: how to handle variable nested depths
- b: how to handle variable keys
I also tried looking to see if lodash had a method (or methods) that could help like:
https://github.com/node4good/lodash-contrib/blob/master/docs/_.object.selectors.js.md#getpath
or:
https://lodash.com/docs/4.17.11#flatMapDeep
But this doesn't help if I don't know the path to the values I need to get.
Is there a way in javascript to recurse through an object and save its keys and value in an array?
 
     
     
     
    