GAS Can I search down instead of across an array using indexOf()

24 Views Asked by At

I have a table in a sheet which acts like a database. A4 holds some maths to tally up the number of entries in the table. It takes ages searching through it using nested for loops, so I wondered if I could put all of the data into an array and then use indexOf() to find a match for a userpermit combination in column 12. It fails (I get -1 back) as it seems the search only works on a one-dimensional array and that seems to be across, not down. I have played with code and searched for comments but to no avail. Any idea. Here is some code I have used so far. Is there any way I can indexOf down rather than across to find the userpermit.

//  get the data
var spreadsheet            = SpreadsheetApp.openByUrl(SHEETURL);
var permitssheet           = spreadsheet.getSheetByName('permits');
var int_uptally            = permitssheet.getRange("A4").getValue();
var ar_permitsdatablock    = permitssheet.getRange(4,12,int_uptally,1).getValues();

//  prepare the response
codestring = "Add permit - checking for an existing permit - "; 

//  do the search
var key = e.parameter.selecteduseremail + "~" + e.parameter.selectedoption;
var permitkeyfound  = ar_permitsdatablock[1].indexOf(key);

//  send the result back
    codestring = codestring + "Block [0]";
    codestring = codestring + ar_permitsdatablock[0];
    codestring = codestring + "<br>"; 
    codestring = codestring + "Block [1]";
    codestring = codestring + ar_permitsdatablock[1];
    codestring = codestring + "<br>"; 
    codestring = codestring + key;
    codestring = codestring + " - key found at = "; 
    codestring = codestring + permitkeyfound;
    codestring = codestring + "<br>"; 
0

There are 0 best solutions below