0

I have an object like this:

var object = {
  a: 5,
  b: ["a", "b"],
  c: {
    a: 1,
    b: 2
  }
}

And I would like to be transformed to a flat one like this:

var output = {
  a: 5,
  b: "a, b",
  "c.a": 1,
  "c.b": 2
}

Is there any function already done about this?

I have a mongodb database that has hierarchy documents and I need them to be converted to a flat one. Thanks

Totty.js
  • 15,563
  • 31
  • 103
  • 175

0 Answers0