Split an Array into Parts

If your Array is too large for certain activities (e.g. sending requests to an API that has rate limits), your best choice is to split your array into multiple parts by "chunking" or "batching" the Array's data.

This code snippet is an easy way to do that, I use it all the time.

function createBatchedArray(data, chunkSize) { const result = [] for(let i=0; i<data.length; i+=chunkSize) { let chunk = data.slice(i, i+chunkSize) result.push(chunk) } return result } // Example Usage // const data = [1,2,3,4,5,6] // let batchedArray = createBatchedArray(data, 3)

NitroGAS Chrome Extension

Want this snippet handy inside the Apps Script editor? NitroGAS gives you free themes and snippets — plus optional Co-Pilot when you want a boost (1-week, 1-month, or yearly passes — no subscription). Happy Coding!

Get the Extension