JavaScript Array Weirdness

For some reason, when I try to loop through a JavaScript array that has only one item, I get an error that the array is undefined. If I add another item to the array, no problem.

This works:

var myArray = new Array(-1, 1);

This doesn’t:

var myArray = new Array(1);

Any idea why? Am I missing something basic here?

UPDATE: Here is sample looping code:

function loop(thisArray) {
  for (i = 0; i < thisArray.length; i++) {
    alert(thisArray[i]);
  }
}

and a test file.

UPDATE #2: Dougal posts a solution in the comments.