Cody Dicken
Cody Dicken

Reputation: 71

Google Sheets for/of loops Missing ; after for-loop initializer

Working in the script editor of Google Sheets I have some for/of loops that USED to work, but now for the last few days just give error "Missing ; after for-loop initializer".

In this example I'm iterating through an HTTP response that I've converted tho JSON object. I'm looking for specific readings to add to the table if they are there. The error comes on the line that the loop is designated. The data I'm iterating through it as JSON response. Each item definitely includes the attributes I'm requesting (in this case 'name' and 'name.make'). I've read everything in the docs, in the Javascript docs I can find, both of the SO posts on this topic. Any help is appreciated.

'''
function buildListOfAllEquipmentInOrg() {
  var allMachines = getEquipmentFromMyjdForOrg();
  var allMachinesJson = JSON.parse(allMachines);
  var values = allMachinesJson.values;
  var thisRow = 2;
  var each;
  var sheet = SpreadsheetApp.getActiveSheet();
  
  // Interate through all of values...one per machine.
  for (each of values) {
    sheet.getRange(thisRow, 1).setValue([each.name]);
  }
  sheet.getRange(thisRow, 2).setValue([each.make.name]);
  measurementsLink = extractMeasurementsLink(link);
  }
'''    

Upvotes: 0

Views: 222

Answers (1)

Cody Dicken
Cody Dicken

Reputation: 71

As @pguardiario mentioned, the For/Of loops were not working because I was no longer using the Chrome V8 App Script Runtime. I simply had to select the 'run' menu and enable it. There is also a banner that appears when you open the script. I grew so accustomed to seeing the banner indicating I was in v8, that when the banner changed to telling me I was not in V8, I just ignored it.

Upvotes: 1

Related Questions