1 // 把一个数组按照一定长度分割成若干数组 2 function group(array, subGroupLength) { 3 let index = 0; 4 let newArray = []; 5 while(index < array.length) { 6 newArray.push(array.slice(index, index += subGroupLength)); 7 } 8 return newArray; 9 } 10 11 let numberArray = [1,2,3,4,5,6,7,8,9,10,11,12];; 12 let groupedArray = group(numberArray, 5); 13 console.log(groupedArray);