const example = {
a: 5,
b: {
c: 57,
d: {
e: 6
}
}
}
'example.b.d.e' : 6
const createPlainObj = (nested, path = '') =>
Object.entries(nested).reduce((obj, [ k, v ]) => {
const newPath = `${path}${path ? '.' : ''}${k}`;
return Object.assign(obj, v instanceof Object
? createPlainObj(v, newPath)
: { [newPath]: v }
);
}, {});
const plain = createPlainObj(example, 'example');