js 一维数组按照条件转化为二维数组
var dataArray = new Array(2000,5000,6000,7000);
var jj=0;
var kk =1;
var bbb = new Array();
for(var r =0;r<dataArray.length;r++){
if(dataArray[r]>4000*kk){
jj=0;
kk++;
}
bbb[kk] = new Array();
bbb[kk][jj]=dataArray[r];
alert(kk+'------'+jj+'-----'+bbb[kk][jj]);
jj++;
}
alert(bbb[2][0]);
为什么bbb[2][0]打印结果是undefined,在循环里面是有数据的
------解决方案-------------------- bbb[kk] = new Array();
-----》
bbb[kk] = bbb[kk]
------解决方案-------------------- new Array();
------解决方案--------------------var dataArray = new Array(2000, 5000, 6000, 7000,9000);
var result = new Array();
for ( var r = 0; r < dataArray.length; r++) {
var seed = Math.floor(dataArray[r]/4000);
result[seed]
------解决方案--------------------
(result[seed]=[]);
result[seed].push(dataArray[r]);
}
var $a = result;