Created
October 21, 2021 05:26
-
-
Save snghnishant/f66f34be8c09a916664e9321f0f914af to your computer and use it in GitHub Desktop.
Array chunks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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