我不知道如何将值推送到动态多维数组。这是我的代码:
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.
我敢肯定我在这里遗漏了一些基本的东西。