我正在尝试制作一个程序,用于组织 Google Sheets 中 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;
}
但我从来没有得到 ifsuccess to = true...这可能是显而易见的,但我以前从未在谷歌脚本(或javascript:P)中进行过编程,有人知道我做错了什么吗?
最佳答案
看起来您正在比较两个数组对象而不是两个字符串。该屏幕截图声称 name 和employee 是具有单个元素的索引数组。
比较每个 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/