Q:

Trying to do essentially a vlookup in an AdWords Script but it takes too long

I'm trying to match the location input (which may be a post code or a neighborhood) to the AdWords location ID.  I have a massive google sheet with almost 100,000 rows with a list of all the post codes, cities, neighborhoods, etc.  and their corresponding IDs, and I'm trying to write a function where you can input post code (for example) and it gives you the location ID.  So far I have:
  var locationSpread = SpreadsheetApp.openById('scriptID');
  var locationSheet = locationSpread.getSheetByName('Sheet1'); 
  var locationRow = locationSheet.getLastRow();

  var locationMatch = function(locationInput) {    

  for (var i = 2; i <= locationRow; i++) {
      var locationName = locationSheet.getRange([i], 2).getValue();
      if (locationName == locationInput) {
          return locationSheet.getRange([i], 1);
      }
    }
  }

  Logger.log(locationMatch('DD7'));

I think that in theory this should work, but the limit for AdWords scripts is 30 minutes and since this has to iterate through so many rows it simply isn't feasible, it's taking over 20 minutes to return the example I'm logging, and the script should be doing this dynamically for a bunch of inputs.  
Is there a faster/better way of doing this?  Or is there an issue with the script itself that's causing it to run so slowly? 

A:

Using .getValues() might be faster.  You'd need to try it out.  
var locationSpread = SpreadsheetApp.openById('asdf');
var locationSheet = locationSpread.getSheetByName('asdf'); 
var locationRow = locationSheet.getLastRow();

Logger.log("Starting!") 
Logger.log("LocationRow: "+locationRow);

function locationMatch(locationInput) {    
  var locationNames = locationSheet.getRange(1, 2,locationRow,2).getValues();
  for (var i = 1; i <= locationRow-1; i++) {
    Logger.log("locationNames[i][0]:"+locationNames[i][0])
    if (locationNames[i][0] == locationInput) {
      return locationSheet.getRange([i], 1);
    }
  }
}

Logger.log("locationMatch Result:"+locationMatch('MA'));

