title: Good idiom to filter out members of an object (javascript)
body: <p>I'd like to remove certain members of an object (for the sake of argument, those whose keys start with '_'). What's an elegant way to do this? The naïve way would be:</p>
  
  <pre><code>for (var i in obj) 
    if (i[0] === '_') 
      delete obj[i];
  </code></pre>
  
  <p>but that modifies the underlying object during the iteration. In Node at least I guess I could</p>
  
  <pre><code>Object.keys(obj).forEach(function (i) { if (i[0] === '_') delete obj[i]; });
  </code></pre>
  
  <p>or restart the iteration each time something's deleted with an awkward nested loop.</p>
  
  <p>Are there any better solutions?</p>
  
  <p>EDIT: In testing just now, in node.js at least, the naïve solution actually seems to work. It certainly is possible that for...in is (required to be) implemented safely. Anyone know?</p>