Created
November 3, 2022 09:10
-
-
Save Kamandlou/996db7f96514208915c64ac51f615c03 to your computer and use it in GitHub Desktop.
Split array into 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
const chunkSize = 10; | |
for (let i = 0; i < array.length; i += chunkSize) { | |
let chunk = array.slice(i, i + chunkSize); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The last chunk may be smaller than chunkSize. For example, when given an array of 12 elements the first chunk will have 10 elements, and the second chunk only has 2.