我正在尝试制作一个程序来组织Google表格中RFID扫描仪的打孔作业...

当我将扫描[i]与员工姓名[j]匹配时,它永远不会成功。

我有一个简单的if语句:

//names[i] is the name of the card for the scan event (card names = employee full name)
var name = names[i];

//the j for loop will check all employee names in the list for a match
var employee = employees[j];
if (name==employee) {
  var ifsuccess = true;
}


但是,我从来没有成功过= true ...这可能很明显,但是我从来没有在google脚本中编程过(或者javascript:P),没有人知道我做错了什么吗?

最佳答案

看起来您正在比较两个Array对象而不是两个字符串。屏幕截图声称姓名和雇员是带有单个元素的索引数组。

要比较每个Array对象内部的字符串数据:

name[0] == employee[0]     // equal value


或更安全一些:

name[0] === employee[0]    // equal value and of the same type

关于javascript - 即使变量匹配,if语句也会失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15590200/

10-11 19:40
查看更多