JavaScript for loop Index becomes arrayIndex

I have the following JavaScript code fragment

var myArray = new Array();
function calculateTime(ip) {
  for (i in ip) {
    if (!i in myArray) {
      myArray[i] = 0;
    } else {
      myArray[i] += 1;

I expect i to be an index but sometimes window.alert prints "arrayIndex" and because of that my code doesn’t work correctly. Can someone explain me the reason?

Source: javascript

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.