function forLoopItems(data) {
for(let item in data) {
console.log(data[item])
}
}
// forLoopItems([1,2,3,4,5,6,7])
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 to reference this code snippet right from your Google Apps Script Project? Check out our NitroGAS Chrome Extension. This tool will help you build your scripts faster than you could imagine. The tool itself and access to the code snippets are 100% FREE - Happy Coding!
Get the Extension