Iterate over object, knowing when you're on the last iteration
<p>I need to iterate over an Object, but know when I'm on the last iteration.  How can I do that?  Objects don't have a "length" attribute, so I can't just count the iteration number and compare it to the length.  I'm tempted to do something like</p>

<pre><code>var len = 0;
for ( key in obj ) {
    len++;
}

var i = 0;
for ( key in obj ) {
    i++;
    var last_iter = (i == len);
    ...
}
</code></pre>

<p>Is there a better way?</p>
