I am trying to write a custom Apps Script Code.gs function. The function is supposed to accept an array parameter from Google Sheets, do some math with it, and then output the number. I am having trouble getting it to accept the array.
For the function:
function Prodmult(legs){
return legs.length;
};
When I call in in Google Sheets with
=Prodmult({1,2,3})
The cell returns 1
How can I handle the array argument properly? I ultimately want to multiply all the numbers in the array together, which is trivial.
{1,2,3}translates to[[1,2,3]]in JavaScript. The length of[[1,2,3]]is1. The length of[[1,2,3]][0]is3.{1;2;3}translates to[[1],[2],[3]]in JavaScript. The length of[[1],[2],[3]]is3. The length of[[1],[2],[3]][0]is1.See my answer for a more detailed explanation on arrays.