This is an archived thread from the StopByte developer forum —
browse all archived threads.
StopByte is now a payments & ecommerce toolkit — check out our
free calculators.
In one of my website pages I have this line of code:
if (username.toLowerCase().includes("admin")) {
// do something...
}
and it works fine in Chrome & edge, but when checked IE it didn’t work the same way and instead it was throwing an error, saying that the "includes()" function cannot be found!
Any ideas would be appreciated.
Thanks
1 Like
sparta
(this.is.sparta)
#2
string.includes() method is not supported by IE, so you’ll have to switch to string.indexOf()
luckily string.indexOf() is supported by all browsers out there, just it returns the first index of the start of the string to be found.
so simply replace your line of code to this:
if (username.toLowerCase().indexOf("admin") >= 0) {
// do something...
}
1 Like
Yassine
(Yassine)
#3
string.indexOf() is surely the way to go. includes() is not as widely supported by all browsers.