谷歌脚本if语句不起作用

时间:2016-11-23 14:45:14

标签: google-apps-script

任何人都可以帮我处理我的剧本。

function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();

var December = ss.getSheetByName("12");
var range = December.getRange("A:A");

var emailRange = range.getValues();

var Form1 = ss.getSheetByName("Form Responses 1");
var emailList = Form1.getRange("K:K").getValues();

for(x in emailRange)
{
  if(x == 0)
    continue
  var email = emailRange[x];
  if(email == "")
    break;

j = 1
for(i in emailList)
{
  var row = emailList[i];

  if(row == "")
  {
    break;
  }
  SpreadsheetApp.getUi().alert(email + " - " + row);
  if(row == email)
    SpreadsheetApp.getUi().alert("OK");
  }
}

if语句if(row == email)无效。我使用了debug,变量是相同的,但它仍然没有得到。

debug screenshot with two variables have same value

1 个答案:

答案 0 :(得分:0)

简短回答

将if(row == email)替换为if(row [0] == email [0])

解释

rowemail属于数组类型。你应该比较他们的元素。