I'm trying to transform a JavaScript object into a text file of string value pairs. Only the deepest values should be retained.
I know how to accomplish the reverse using lodash
..
_.set(obj, 'a.b.c', 1)
..very easy, but I'm not sure how to accomplish the reverse. I looked through the lodash documentation, but I couldn't find anything close.
Here is an example of what I am trying to accomplish:
Input
const obj = {
a: {
b: {
c: 1,
d: 2,
e: 3
}
}
}
toKeyValues(obj)
Desired output (string)
a.b.c 1
a.b.d 2
a.b.e 3