Last loop in for()?

javascript

Solution

First off, keys don't come in any guaranteed order. By specification, the keys are unordered. If you really wanted to do something with the last key you got, you could do so like this;

var lastkey;
for( var key in obj ){
    lastkey = key;
    blah.blah()
}
if(choice){
    // use lastkey if you want
    doThis();
}

Problem

I have been struggling with this for a while: ``` for( var key in obj ){ blah.blah() if(choice){ doThis(); } } ``` How can I call `doThis()` only at the last item? Since I don't have a counter, `i`, I can't determine which is the last item.

Original source