I've come across code like this multiple times:
function customArrayIndexOf(item, array){
for (var i = 0, l = array.length; i < l; i++) {
if (i in array && array[i] === item) return i;
}
return -1;
}
But I'm unsure about the necessity of i in array
.
My queries are:
- What is its purpose?
- Is it really needed?
- When will it not work without it?