3
我無法弄清楚如何將值推送到動態多維數組。這是代碼我有:如何將值推送到多維數組
function compareNumbers(){
var count = $('.finishedRow').length;
var inputtedNums = new Array();
for(var i=0; i<count; i++){
$('.finishedRow').eq(i).find('li').each(function(j){
inputtedNums[i].push($(this).text());
});
}
console.log(inputtedNums);
}
所以說,有,例如,3個finishedRow
選擇器,並且每個選擇器finishedRow
包含4個li
元件與first
,second
,third
,fourth
值。我希望我的inputtedNums
變量的樣子:
inputtedNums = [
["first", "second", "third", "fourth"],
["first", "second", "third", "fourth"],
["first", "second", "third", "fourth"]
]
由於我的代碼現在我得到的錯誤:Cannot call method 'push' of undefined
。
我確定我在這裏錯過了一些基本的東西。
我知道解決方案可能很簡單,但並不認爲它會那麼簡單!謝謝 – garethdn
嗨,我怎麼能把變量的關鍵入你的解決方案? –