Last active
August 21, 2018 02:55
-
-
Save visualjeff/2d0bdd1a78e6249d6823a8cbb2a9c2d6 to your computer and use it in GitHub Desktop.
Chunking arrays
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
//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