title: Traverse all nodes and yield keys and value in Javascript
body: <p>Given a JSON structure</p>
  
  <pre><code>var json = {
    'a': {
      'a1': ['a1a', 'a1b', 'a1c'],
      'a2': ['a2a', 'a2b'],
      'a3': []
    },
    'b': {
      'b1': ['b1a', 'b1b', 'b1c', 'b1d'],
      'b2': ['b2a', 'b2b'],
    },
    'c': ['c1', 'c2'],
    'd': {
      'd1': ['d1a', 'd1b', 'd1c'],
      'd2': []
    },
    'e': ['e1', 'e2'],
    'f': [
      'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10'
    ]
  };
  </code></pre>
  
  <p>Using Javascript how can I traverse this to <strong>yield</strong> an array of all keys and values?  In other words, without simply keeping an external store and append to it as I traverse, how can I return an array of the entire set of node keys and values?</p>
  
  <p>For example in Python I might make use of a generator.  So perhaps I should ask, how can I use a generator in Javascript?</p>
  
  <p>Javascript example with jQuery:</p>
  
  <pre><code>function traverse(jsonObj) {
    if( typeof jsonObj == "object" ) {
      $.each(jsonObj, function(k,v) {
        traverse(v);
      });
    }
    else {
      // how can I yield this value instead?
      console.log(jsonObj)
    }
  }
  </code></pre>
  
  <p>Where my expected output would be an array of all keys and values:</p>
  
  <pre><code>['a', 'a1', 'a1a', 'a1b', 'a1c', 'a2', 'a2a', 'a2b'] // ... and so on
  </code></pre>