gpt4 book ai didi

javascript - 如何使用 JavaScript 构建数组的数组?

转载 作者:行者123 更新时间:2023-11-28 11:17:23 25 4
gpt4 key购买 nike

我的输出应该是这样的:(例如数据)

myArray = [ [otherArray0], [otherArray1], [otherArrayN] ]

我的尝试:

var myArray = [];
var num = 50;
for (i=0; i<num;i++)
{

var a = 0;
$('#divID .class select[value!=""]').each(function() //get values from a select
{
var otherArray+i = []; //each for cycle is a new "sub array"
otherArray+i[a] = $(this).val(); //store in array the values from select
a++
})
}

我思考得好吗?

最佳答案

首先

otherArray[i] = []; // create a new array

然后

otherArray[i][a] = $(this).val();

但是你的代码可以变得更简单

var myArray = [];
var num = 50;
for (i=0; i<num;i++)
{
myArray.push($.map($('#divID .class select[value!=""]'),function(e){
return e.val();
}));
}

关于javascript - 如何使用 JavaScript 构建数组的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14631252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com