The following code results in the console printing "Z".
<script>
var x = new Array(new Array());
x[0][0] = "Z";
console.log(x[0][0]);
</script>
But if I replace x[0][0] = "Z" with a nested for loop of arbitrary dimensions ...
<script>
var x = new Array(new Array());
for(i=0;i<5;i++){
for(j=0;j<3;j++){
x[i][j] = "Z";
}
}
console.log(x[0][0]);
</script>
... it gets stuck on the very zeroth iteration, despite that being the same instruction (as far as I see) as given in the first one. According to both Chrome and Firefox output, it suddenly considers x[0][0] to be undefined.
What's the deal?
x[1][0]
will throw an error, since your outer array only has one element. – Felix Kling Nov 18 '13 at 2:50