title: Iterate over object keys in node.js
body: <p>Since Javascript 1.7 there is an <a href="https://developer.mozilla.org/en/New_in_JavaScript_1.7#Iterators">Iterator</a> object, which allows this:</p>
  
  <pre><code>var a={a:1,b:2,c:3};
  var it=Iterator(a);
  
  function iterate(){
      try {  
          console.log(it.next());
          setTimeout(iterate,1000);
      }catch (err if err instanceof StopIteration) {  
          console.log("End of record.\n");  
      } catch (err) {  
          console.log("Unknown error: " + err.description + "\n");  
      }  
  
  }
  iterate();
  </code></pre>
  
  <p>is there something like this in node.js ?</p>
  
  <p>Right now i'm using:</p>
  
  <pre><code>function Iterator(o){
      /*var k=[];
      for(var i in o){
          k.push(i);
      }*/
      var k=Object.keys(o);
      return {
          next:function(){
              return k.shift();
          }
      };
  }
  </code></pre>
  
  <p>but that produces a lot of overhead by storing all the object keys in <code>k</code>.</p>