Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

chunking array javascript

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;
},[[]])
Source by anonystick.com #
 
PREVIOUS NEXT
Tagged: #chunking #array #javascript
ADD COMMENT
Topic
Name
3+5 =