Skip to content

Instantly share code, notes, and snippets.

@fostyfost
Created October 8, 2021 09:04
Show Gist options
  • Save fostyfost/36adededde5f4241b6532cfeaae59eb1 to your computer and use it in GitHub Desktop.
Save fostyfost/36adededde5f4241b6532cfeaae59eb1 to your computer and use it in GitHub Desktop.
Split Array Into Chunks
export const getChunks = <T = unknown>(arr: T[], length: number = 1): T[][] => {
const chunks = []
for (let index = 0; index < arr.length; index += length) {
chunks.push(arr.slice(index, index + length))
}
return chunks
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment