Skip to content

Instantly share code, notes, and snippets.

@snghnishant
Created October 21, 2021 05:26
Show Gist options
  • Save snghnishant/f66f34be8c09a916664e9321f0f914af to your computer and use it in GitHub Desktop.
Save snghnishant/f66f34be8c09a916664e9321f0f914af to your computer and use it in GitHub Desktop.
Array chunks
let array = [1,2,3,4,5,6,7,8,9,10,11,12,13];
const arrayToChunks = (arr, chunkSize) => {
let i,
j,
chunks = [];
for (i = 0, j = arr.length; i < j; i += chunkSize) {
chunks.push(arr.slice(i, i + chunkSize));
}
return chunks;
};
Promise.all(
// To be sent in groups of 1000
arrayToChunks(array, 5).map(chunk => console.log(chunk)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment