我试图在删除新行输入后在两个字符串之间创建比较。但是,当对字符串使用 split 方法时,由于字符串中添加了逗号(,),因此比较失败。无法弄清楚为什么会出现这种情况。感谢您的帮助
var test_Array = ['Chess', 'Chess\n'];
if (test_Array[0] == test_Array[1].split('\n'))
{
console.log('Test');
}
console.log(test_Array[0] + ' - ' + test_Array[1].split('\n'));
尝试这样:
function myfunk() {
var test_Array = ['Chess', 'Chess\n'];
if (test_Array[0] == (test_Array[1].split('\n')[0])) {
Logger.log('Test');
}
Logger.log(test_Array[0] + ' - ' + test_Array[1].split('\n')[0])
}
逗号只是分割的默认分隔符
Execution log
9:55:06 AM Notice Execution started
9:55:07 AM Info Test
9:55:07 AM Info Chess - Chess
9:55:08 AM Notice Execution completed