Created
February 28, 2022 14:59
-
-
Save rjchicago/b558fba5466cc97530e7c515067798fc to your computer and use it in GitHub Desktop.
chunk large object arrays to string
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
# chunk array to string | |
private *arr2chunks(arr: any[], n: number) { | |
for (let i = 0; i < arr.length; i += n) { | |
const str = JSON.stringify(arr.slice(i, i + n)) | |
const open = i === 0 ? '[':''; | |
const close = n*(i+1) < arr.length ? ',' : ']'; | |
yield `${open}${str.slice(1, str.length-1)}${close}`; | |
} | |
yield null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment