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);
原文地址:https://www.cnblogs.com/yinhao-jack/p/10759820.html
时间: 2024-10-13 06:23:50