我試圖推動新的數組的一個數組的位置:推新陣列爲二維陣列
var history = [ ];
function addHistory(array)
{
history.push(array);
console.log(history)//to check what is the value of array
}
var test1 = [0,0,0,0,0];
var test2 = [1,1,1,1,1];
addHistory(test1);
addHistory(test2);
做這樣後,數組應該是:
[ [0,0,0,0,0] , [1,1,1,1,1] ]
而是將其打印
[ [1,1,1,1,1] , [1,1,1,1,1] ]
所以基本上它取代所有舊的陣列,陣列「歷史」,inste推廣到最後的廣告。
這裏有什麼問題?
非常感謝
編輯:
對不起,忘了提,我的實際變量不叫歷史(我把它叫做這樣只是你能想象我想要的)。它被稱爲「rollHist」
對不起,我的錯,它與每一個名字相同..也許有插入新陣列的另一種方式成數組? – Nedas