When I first declare an array called emptyline like this:
var emptyline=[];
for (var i=0;i<10;i++)
emptyline.push(-1);
Then I make a 2D array using it:
var c=[];
for (var i=0;i<20;i++) c.push(emptyline);
And finally I set an element like this:
c[1][6]=3;
It looks like this when I type c
in the Chrome/Safari Console:
[
Array[10]
//...
4: -1
5: 0
6: 3
7: -1
//...
,
Array[10]
//...
4: -1
5: 0
6: 3
7: -1
// etc.
]
In some cases index 5 is 0, in some it is -1. Why does this happen and how can I fix it?