javascript - How do I remove the last item of an array inside of an array -


how remove last item of array inside of array. in case, want remove null @ end of array inside of array. here's code

function chunkarrayingroups(arr, size) {   // break up.   var arrwithsubarr = [];    for(var = 0; < arr.length / size; i++){     arrwithsubarr.push([]);   }   var index = 0;   var whichsubarr = 0;   for(whichsubarr = 0; whichsubarr < arr.length / size; whichsubarr++){     for(i = 0; < size; index++){       arrwithsubarr[whichsubarr].push(arr[index]);       i++;     }   }    return arrwithsubarr; }  chunkarrayingroups([0, 1, 2, 3, 4, 5], 4); 

i believe ultimate goal split original array number of arrays each equal or less size specified (in case last sub array not equal size). rather removing undefined values added in loop easier prevent them getting inserted @ all.

function chunkarrayingroups(arr, size) {   // break up.   var arrwithsubarr = [];    var whichsubarr = 0;    // using math.ceil returns smallest integer greater or equal number   // in case minimum number of sub arrays needed contain items of original array   var numofsubarrs = math.ceil(arr.length/size);    // create empty sub arrays   for(var = 0; < numofsubarrs; i++){     arrwithsubarr.push([]);   }    (var =0; < arr.length; i++) {       arrwithsubarr[whichsubarr].push(arr[i]);       // starting inital sub array @ position 0       // increment next sub array once current 1 equal specified size       if (arrwithsubarr[whichsubarr].length == size){           whichsubarr++;       }   }    return arrwithsubarr; }  chunkarrayingroups([0, 1, 2, 3, 4, 5], 4); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -