Right now I'm working on a project and I need to append a certain variable to an array. What I need to do is to read values from a spreadsheet and extract values that meet a certain criterion.
In mathematica I will do it like this
If[IFin="RECIBIDO",
(*If true, do nothing*),
(*else*) AppendTo[pendientes,{"project#", "IFin", IFin}]
]
But I need to apply it in a google sheets script, so right now I'm trying this (I'm using a switch case structure because of my needs)
var IFin=0 //it can take the following values 0, 1, 2, 3, "RECIBIDO"
var pendientes=[];
var InfOK = "RECIBIDO";
switch(IFin){
case InfOk:
break;
case 0:
[i,"IFin",IFin].appendTo(pendientes);
break;
case 1:
[i,"IFin",IFin].appendTo(pendientes);
break;
case 2:
[i,"IFin",IFin].appendTo(pendientes);
break;
case 3:
[i,"IFin",IFin].appendTo(pendientes);
break;
}
And all it says when I try to run it is "TypeError: Could not find funcion appendTo". I'm new to google scripts, and hence I'm using this .asp I've searched the google help and it has an extensive explanation of sheets functions.
Solution
This made me understand the root of the problem but proposed solution hasn't been tested yet:
appendTo isn't an array method in javascript. You could do something like pendientes = pendientes.concat([i,"IFin",IFIN])
This helped me solve the problem:
Try using push(). This method adds one or more elements to the end of an array and returns the new length of the array.
So by replacing
[i,"IFin",IFin].appendTo(pendientes);
by
pendientes.push([i,"IFin",IFin]);
my code worked just fine.