var array = [];
var arr = [];
var i;
for (i = 0; i < 2; i++) {
var temp = [];// using array[i] = new Array() works fine
array.push(temp);
arr.push(temp);
}
array[0].push(1);
arr[0].push(2);
alert(array[0]);
The above javascript code gives [1,2] as out put. Where as using 'new Array()' instead of 'push([])' gives [1]. I was able to find the issue, but I don't get reason why. can some one explain this
array[0]andarr[0]refer to the same array.