Skip to content

Instantly share code, notes, and snippets.

@rjchicago
Created February 28, 2022 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjchicago/b558fba5466cc97530e7c515067798fc to your computer and use it in GitHub Desktop.
Save rjchicago/b558fba5466cc97530e7c515067798fc to your computer and use it in GitHub Desktop.
chunk large object arrays to string
# 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