I'm writing a google apps script where I get the values from a spreadsheet..but since I need to see if there is a match with a variable, I need to do make sure the values are in lowercase.
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var column = sheet.getRange(A:A);
var values = column.getValues();
then I want to loop through the values to see if there is a match, like this: row=0;
while ( values[row] && values[row][0] !== data ) {
// do something
row ++;
}
My question is this..while I can make sure the variable "data" is lowercase, how can I make sure values[row] and values[row][0] are also lowercase?
You can loop through the values with checking lower case item,
for (var row in values)
{
if(values[row][0].toString().toLowerCase() !== data )
{
// do something
}
}
this is values[row]
an array, what do you mean by lower case of it?
So first of all I believe that with the notation you're using .getRange
would take a string like "A:A"
as an argument to return the range containing all values in column A.
Use Logger.log()
and typeof
to check the type of the values being returned.
values
will be a two-dimensional array, with each child array containing the value for each respective cell.
values[row]
will return an array representing the cell at the index of row
. An array cannot be lowercase obviously.
values[row][0]
will return the value in the cell. You can coerce the value to a string (to make sure it's always a string) by concatenating it with an empty string (values[row][0]+"")
, and then you can apply the usual built-in JS toLowerCase() method, like so: (values[row][0]+"").toLowerCase();
So (values[row][0]+"").toLowerCase() !== data
should achieve what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With