I have the following JavaScript code fragment
var ip = new Array();
// This array filled with values and passed to function
function calculateTime(ip) {
for (i in ip) {
window.alert(i);
if (!i in myArray) {
myArray[i] = 0;
} else {
myArray[i] += 1;
}
}
}
I expect i
to be an index (0, 1, 2 ...) but sometimes window.alert
prints "arrayIndex"
and because of that my code doesn't work correctly. Can someone explain me the reason? I am new in JavaScript.