Skip to content

Instantly share code, notes, and snippets.

@Kamandlou
Created November 3, 2022 09:10
Show Gist options
  • Save Kamandlou/996db7f96514208915c64ac51f615c03 to your computer and use it in GitHub Desktop.
Save Kamandlou/996db7f96514208915c64ac51f615c03 to your computer and use it in GitHub Desktop.
Split array into chunks
const chunkSize = 10;
for (let i = 0; i < array.length; i += chunkSize) {
let chunk = array.slice(i, i + chunkSize);
}
@Kamandlou
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment