[英]Sheets: indexOf not finding substring
Working in apps script I have : 在应用程序脚本中工作,我有:
var conversations = row['CONVERSATION'].split('|');
var replies = conversations.map(function(message) { //ONLY CHECKED ROWS.
var m = message.toString();
return m.indexOf('R:')==true;
});
Logger.log(conversations);
Logger.log(replies);
When I look at the logs: 当我查看日志时:
[19-03-08 11:51:12:892 EST] [R: test3 , R: test3 , tx]
[19-03-08 11:51:12:893 EST] [false, true, false]
Why is the first element in the replies array false. 为什么replies数组中的第一个元素为false。 Shouldn't it be true?
难道不是真的吗?
Why is the first element in the replies array false.
为什么replies数组中的第一个元素为false。 Shouldn't it be true?
难道不是真的吗?
So if the indexOf matches first element you get index as 0
and your condition is checking for true
values but 0
is not so it is returning you false. 因此,如果indexOf匹配第一个元素,则将index设置为
0
并且您的条件是检查true
值,但0
不是,因此返回false。
This will fail if your matched index is 0
如果您匹配的索引为
0
则此操作将失败
m.indexOf('R:') === true
Better you just check 更好的就是检查
m.indexOf('R:') !== -1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.