flattening the nested object in javascript
I ran into this problem, I was able to write solution which can handle array of object (not posted here) or one level deep nested object but i couldn't solve when the given object has nested structure like below. I am curious to know how we can solve this. const source = { a: 1, b: { c: true, d: { e: 'foo' } }, f: false, g: ['red', 'green', 'blue'], h: [{ i: 2, j: 3 }] }; solution should be const solution = { 'a': 1, 'b.c': true, 'b.d.e': 'foo', 'f': false, 'g.0': 'red', 'g.1': 'green', 'g.2': 'blue', 'h.0.i': 2, 'h.0.j': 3 }; attempt for one deep nested object let returnObj = {} let