title: How to create a recursive object tree array for later iteration?
body: <p>My question is slightly <a href="https://stackoverflow.com/questions/15690706/recursively-looping-through-an-object-to-build-a-property-list">similar to this one</a>.</p>
  
  <p>So, say I have an object like this:</p>
  
  <pre><code>var obj = {
    'a': {
      'b': {
        'c': 1,
        'd': 2
      },
      'e': 3
    },
    'f': 4,
    'g': 5
  };
  </code></pre>
  
  <p>I want to run that through a function and create an array that looks something like this:</p>
  
  <pre><code>var arr =
    'a',
    'a.b',
    'a.b.c',
    'a.b.d',
    'a.e',
    'f',
    'g'
  ];
  </code></pre>
  
  <p>The purpose of that array is so that I can later loop through objects with the same hierarchial format in the same exact same way. I'm unsure about how to do this step.</p>
  
  <p>So, given <code>obj</code> and <code>arr</code>, it would use a <code>for</code> loop to access all the key-value pairs in <code>obj</code>. As far as I know, you can't access a nested property like this: <code>obj['a.b.c']</code>, so I'm not exactly sure how to do this.</p>
  
  <p><strong>Clarification Edit:</strong></p>
  
  <p>After this array is created, I'm wondering how to use it to loop through objects of the same format in the way described by the array. For example</p>
  
  <pre><code>function iterateAnotherObjectWithSameFormat(aObj) {
    for (var i = 0; i &lt; arr.length; i++) {
      // access aObj['a'], then aObj['a.b'], then aObj['a.b.c'], etc..
    }
  }
  </code></pre>