Skip to content

Instantly share code, notes, and snippets.

@visualjeff
Last active August 21, 2018 02:55
Show Gist options
  • Save visualjeff/2d0bdd1a78e6249d6823a8cbb2a9c2d6 to your computer and use it in GitHub Desktop.
Save visualjeff/2d0bdd1a78e6249d6823a8cbb2a9c2d6 to your computer and use it in GitHub Desktop.
Chunking arrays
//You could use faker.js to generate some testData
function chunk(arr, chunkSize) {
const R = [];
for (let i = 0, len = arr.length; i < len; i += chunkSize) {
R.push(arr.slice(i, i + chunkSize));
}
return R;
}
//If necessary, you can convert Object properties to an Array
//const testData = Object.keys(payload).map(i => payload[i]);
//Chunk the array. 10 objects per array.
const chunkedArray = chunk(testData, 10);
console.log(chunkedArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment