hi
I was working on a script that notifies users via email when certain conditions are met. I store all user emails in a string, which I get from a single cell in a spreadsheet, but the error occurres if you simply declare a string variable yourself. The .includes() method seems to not work properly on strings and I'm not sure why.
The following code throws "TypeError: Cannot find function includes in object
a...@a.com,b...@bla.bla." error. The variable allEmails is naturally a string, I even checked this with typeof, just to be sure.
if(allEmails.includes(",")) {
Logger.log("Multiple emails: " + allEmails.split(","));
} else {
Logger.log("One email: " + allEmails);
}
However, the following script that does practically the same thing works just fine:
if(allEmails.indexOf(",")>-1) {
Logger.log("Multiple emails: " + allEmails.split(","));
} else {
Logger.log("One email: " + allEmails);
}
So yeah... I can get this to work by a rather simple workaround I'm just curious why indexOf() works while includes() doesn't.