<p>What's the fastest way to count the number of keys/properties of an object? Is it possible to do this without iterating over the object?  I.e., without doing:</p>
<pre><code>var count = 0;
for (k in myobj) if (myobj.hasOwnProperty(k)) ++count;
</code></pre>
<p>(Firefox did provide a magic <code>__count__</code> property, but this was removed somewhere around version 4.)</p>

If you are actually running into a performance problem I would suggest wrapping the calls that add/remove properties to/from the object with a function that also increments/decrements an appropriately named (size?) property.
You only need to calculate the initial number of properties once and move on from there. If there isn't an actual performance problem, don't bother. Just wrap that bit of code in a function
```
getNumberOfProperties(object)
```
and be done with it.