Answers for "how to divide array in two parts in js"

0

how to divide array in two parts in js

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 two parts in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language