In google Apps script i am pulling rows of numbers into an array
I need to find the sum of every element in that array
This code works fine: (This is pulling the values into the array)
var test = [];
test = sheet.getRange(13, 6, 4, 24).getValues();
I’ve tried a couple different formulas i’ve found and haven’t been able to get it to work right:
function testSum (test) {
let total = 0;
for (const i of test) {
total += i;
}
return total;
}
var test1 = test.flat();
var test1 = test.reduce((a, b) => a + b, 0);
Tried everything i could find and nothing would work
3
Answers
There are other ways to find sum as well, but I used
array.reduce
onethis code will be make the mistake solucion.