I have an array of map points that contain speeds and I want to create a new array of every 25 points and push them into another array called chunks. So this is what I am doing:
var chunks = []; // the array of chunks
var tempArray = []; //used for storing current chunk
var currentLoop = 0; //used for checking how many items have been taken
for (var i = 0; i < gon.map_points.length; i++) {
if (currentLoop == 26) { // if the current items stored is above 25
chunks.push(tempArray); // push the chunk
currentLoop = 0; // reset the count
tempArray = []; // reset the chunk
}
tempArray.push(gon.map_points[i].speed); // add item into chunk
currentLoop++; // increase count
}
So this works fine unless the array of map points isn't a perfect number of points (e.g. it might be 117), so then I won't get the last 17 points added to my chunks array.
Is there a way to chunk up the array into 25 points regardless of the total items?