Skip to content

Instantly share code, notes, and snippets.

@sean-codes
Last active Sep 15, 2017
Embed
What would you like to do?
Javascript Split Array into Chunks
function splitArrayIntoChunks(arr, chunkLen){
var chunkList = []
var chunkCount = Math.ceil(arr.length/chunkLen)
for(var i = 0; i < chunkCount; i++){
chunkList.push(arr.splice(0, chunkLen))
}
return chunkList
}
var testArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
var chunks = splitArrayIntoChunks(testArray, 3)
console.log(chunks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment