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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With