一个数组按照固定的个数分成多个数组,用于分页
function getNewArray(array, subGroupLength) {
let index = 0;
let newArray = [];
while(index < array.length) {
newArray.push(array.slice(index, index += subGroupLength));
}
return newArray;
}
var arr= [1,2,3,4,5,6,7,8,9,10,11,12];;
var nArr= getNewArray(arr, 8);
//得到的nArr数组为:
nArr[[1,2,3,4,5,6,7,8],[9,10,11,12]]
浙公网安备 33010602011771号