How do you determine the number of defined elements in an array?
<p>If I have an array in Javascript that has been filled sporadically, how do I determine the number of non-nothing elements in the array?</p>

<p>for example:</p>

<pre><code>var zipCodes = [];
zipCodes[10006] = 'New York, NY';
zipCodes[90210] = 'Los Angeles, CA';
</code></pre>

<p>zipCodes.length returns 90,211 here and I really don't want to loop through 90,209 nothings to find out I have two valid elements. Using a for-in loop means dealing with anything that might bubble up the prototype chain and trying to figure out if it's part of <em>this</em> array.</p>

<p>Is there any way, given the array defined above, I can extract "2" as the number of defined elements?</p>
