Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dictionary Google应用程序脚本中的字典语法错误_Dictionary_Google Apps Script_Syntax - Fatal编程技术网

Dictionary Google应用程序脚本中的字典语法错误

Dictionary Google应用程序脚本中的字典语法错误,dictionary,google-apps-script,syntax,Dictionary,Google Apps Script,Syntax,我有一个函数,它根据工作表中的一系列值创建字典。然后,我尝试使用键从该表中提取一个值。登录到控制台工作正常。但是,在if语句中,它只表示语法错误,而不表示其他内容。我想不出来。下面是崩溃的函数和代码。此问题只发生在for循环中,不会发生在for循环之外 //creates dictionary function columnLocationWithNotation(notation) { var spreadsheet = SpreadsheetApp.openByUrl(); var

我有一个函数,它根据工作表中的一系列值创建字典。然后,我尝试使用键从该表中提取一个值。登录到控制台工作正常。但是,在if语句中,它只表示语法错误,而不表示其他内容。我想不出来。下面是崩溃的函数和代码。此问题只发生在for循环中,不会发生在for循环之外

//creates dictionary
function columnLocationWithNotation(notation) {
  var spreadsheet = SpreadsheetApp.openByUrl();
  var sheet = spreadsheet.getActiveSheet();
  var data = sheet.getDataRange();
  var cells = data.getValues();
  var dictionary = {};

  switch (notation) {
    case "zeroIndex":
      for (var i = 0; i < sheet.getLastRow(); i++) {
        dictionary[cells[i][0]] = cells[i][1]  
      } 
      return dictionary
      break;
    case "regularIndex": 
      for (var i = 0; i < sheet.getLastRow(); i++) {
        dictionary[cells[i][0]] = cells[i][2]
      }
      return dictionary
      break;
    case "string": 
      for (var i = 0; i < sheet.getLastRow(); i++) {
        dictionary[cells[i][0]] = cells[i][3]
      }
      return dictionary
      break;             
  }
}

var master0indexDictionary = columnLocationWithNotation("zeroIndex")

for (var i = 1; i =< (sheet.getLastRow() - 1); i++) {
  var phone = master0indexDictionary["Tutor Name"]
  if (cells[i][phone] === phoneNumber) { //LINE WITH SYNTAX ERROR
    //do something

}
//创建字典
函数columnLocationWithNotation(notation){
var电子表格=SpreadsheetApp.openByUrl();
var sheet=spreadsheet.getActiveSheet();
var data=sheet.getDataRange();
var cells=data.getValues();
var字典={};
开关(符号){
案例“零索引”:
对于(var i=0;i
即使您的脚本存在许多其他问题,也不是突出显示的行导致了问题。没有'=如果(cells[i][phone]==phoneNumber){columnLocationWithNotation()中定义的
cells
cells没有为
行定义
cells
不能在函数外部使用。如果
单元格
在同一范围内定义,如果(cells[i][phone]==phoneNumber){
,我们可以在没有您私人信息的情况下向您介绍错误消息和整个脚本吗?
for (var i = 1; i <= (sheet.getLastRow() - 1); i++) {
 return dictionary;
      break;
 return dictionary
      break;    

  var phone = master0indexDictionary["Tutor Name"]
var a = {name: 'John'}  //no semicolon
[a].forEach(function(element) {
  Logger.log(element);    //logs undefined
  })