title: flattening the nested object in javascript
body: <p>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.</p>
  
  <pre><code>const source = {
    a: 1,
    b: {
      c: true,
      d: {
        e: 'foo'
      }
    },
    f: false,
    g: ['red', 'green', 'blue'],
    h: [{
      i: 2,
      j: 3
    }]
  };
  </code></pre>
  
  <p>solution should be</p>
  
  <pre><code>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
  };
  </code></pre>
  
  <p>attempt for one deep nested object </p>
  
  <pre><code>let returnObj = {}
  
  let nestetdObject = (source, parentKey) =&gt; {
  
      let keys = keyFunction(source);
  
      keys.forEach((key) =&gt; {
        let values = source[key];
  
        if( typeof values === 'object' &amp;&amp; values !== null ) {
          parentKey = keys[0]+'.'+keyFunction(values)[0]
          nestetdObject(values, parentKey);
        }else{
          let key = parentKey.length &gt; 0 ? parentKey : keys[0];
          returnObj[key] = values;
        }
      })
      return returnObj
  };
  
  // Key Extractor 
  let keyFunction = (obj) =&gt;{
    return Object.keys(obj);
  }
  </code></pre>
  
  <p>calling the function</p>
  
  <pre><code>nestetdObject(source, '')
  </code></pre>
  
  <p>But my attempt will fail if the object is like <code>{ foo: { boo : { doo : 1 } } }</code>. </p>