non*_*ipt 0 javascript arrays jquery
我的输出应该是这样的:(例如数据)
myArray = [ [otherArray0], [otherArray1], [otherArrayN] ]
Run Code Online (Sandbox Code Playgroud)
我的尝试:
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++
})
}
Run Code Online (Sandbox Code Playgroud)
我在想什么?
首先
otherArray[i] = []; // create a new array
Run Code Online (Sandbox Code Playgroud)
然后
otherArray[i][a] = $(this).val();
Run Code Online (Sandbox Code Playgroud)
但是你的代码可以变得更简单
var myArray = [];
var num = 50;
for (i=0; i<num;i++)
{
myArray.push($.map($('#divID .class select[value!=""]'),function(e){
return e.val();
}));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
80 次 |
| 最近记录: |