Consider following code:
var arr = [111, 222, 333];
for(var i in arr) {
if(i === 1) {
// Never executed
}
}
It will fail, because typeof i === 'string'.
Is there way around this? I could explicitly convert i to integer, but doing so seems to defeat the purpose using simpler for in instead of regular for-loop.
Edit:
I am aware of using == in comparison, but that is not an option.
==so no type check will be includedforloop for iterating arrays.iand why is a Stringfor…inenumerations on arrays! Just because a hammer is a simpler tool than an electric screwdriver, you shouldn't use it for screws.