Looping in Google Apps Script

Let’s say you pass an array of values to be processed to a custom function, and you want to loop through them.  In these examples, we’ll just go through each value and sum it if it is a number.

The traditional for loop

In this case, an index is used for each dimension of the values, using the .length property of the array to loop through the rows, then the columns, of the passed values.