const chunkLength=2; const res=[1,2,3,4,5,6,7].reduce((acc,curr)=>{ if(acc[acc.length-1].length>chunkLength){ acc=[...acc,[curr]] }else{ acc[acc.length-1].push(curr) } return acc; },[[]])