2

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
simonwjackson
  • 1,818
  • 4
  • 25
  • 33
  • Look at https://stackoverflow.com/q/44395675/6230850 it's not exactly the same question but it's a start point – Bibzer Jun 08 '17 at 07:48

0 Answers0