Answers for "how to divide array in chunks"

0

how to divide array in chunks

function chunkArray(arr,n){
     var chunkLength = Math.max(arr.length/n ,1);
     var chunks = [];
     for (var i = 0; i < n; i++) {
         if(chunkLength*(i+1)<=arr.length)chunks.push(arr.slice(chunkLength*i, chunkLength*(i+1)));
     }
     return chunks; 
 }
Posted by: Guest on March-26-2021

Code answers related to "how to divide array in chunks"

Code answers related to "Javascript"

Browse Popular Code Answers by Language