js数组分组

let i, j, chunkedArray = [], chunk = 4;
let posts = [1,4,5,7,9,12,14,16,23,26,37,48,21,52,43,25];

for (i=0, j=0; i < posts.length; i += chunk, j++) {
     chunkedArray[j] = posts.slice(i,i+chunk);
}
console.log(chunkedArray);

 

posted @ 2018-06-28 10:05  土豆儿哥  阅读(417)  评论(0编辑  收藏  举报