数组 [1,2,3,4,5] 格式化成 [[1,2,3],[4,5]]
let k=[];[1,2,3,4,5,6].map((value,index) => { k[~~(index/3)] = k[~~(index/3)]==undefined?[]: k[~~(index/3)]; k[~~(index/3)].push(value); });console.log(k);
数组 [1,2,3,4,5] 格式化成 [[1,2,3],[4,5]]
let k=[];[1,2,3,4,5,6].map((value,index) => { k[~~(index/3)] = k[~~(index/3)]==undefined?[]: k[~~(index/3)]; k[~~(index/3)].push(value); });console.log(k);