Created
October 8, 2021 09:04
-
-
Save fostyfost/36adededde5f4241b6532cfeaae59eb1 to your computer and use it in GitHub Desktop.
Split Array Into Chunks
This file contains hidden or 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
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