title: How to quickly clear a JavaScript Object?
body: <p>With a JavaScript Array, I can reset it to an empty state with a single assignment:</p>
  
  <pre><code>array.length = 0;
  </code></pre>
  
  <p>This makes the Array "appear" empty and ready to reuse, and as far as I understand is a single "operation" - that is, constant time.</p>
  
  <p>Is there a similar way to clear a JS Object? I know I can iterate its fields deleting them:</p>
  
  <pre><code>for (var prop in obj) { if (obj.hasOwnProperty(prop)) { delete obj[prop]; } }
  </code></pre>
  
  <p>but this has linear complexity.</p>
  
  <p>I can also just throw the object away and create a new one:</p>
  
  <pre><code>obj = {};
  </code></pre>
  
  <p>But "promiscuous" creation of new objects leads to problems with Garbage Collection on IE6. (<a href="http://ajaxian.com/archives/garbage-collection-in-ie6" rel="noreferrer">As described here</a>)</p>