I\'m using this function to create chunks of an array:
function chunkArray(myArray, chunk_size) {
let results = [];
while (myArray.length) {
You could use the remainder of the index with the wanted size for the index and push the value.
var array = [1, 2, 3, 4, 5, 6],
size = 3,
result = array.reduce((r, v, i) => {
var j = i % size;
r[j] = r[j] || [];
r[j].push(v);
return r;
}, []);
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }