正如你所写的,Internet Explorer (或 Opera)不支持 String.prototype.includes。
Instead you can use String.prototype.indexOf. #indexOf returns the index of the first character of the substring if it is in the string, otherwise it returns -1. (Much like the Array equivalent)
var myString = 'this is my string';
myString.indexOf('string');
// -> 11
myString.indexOf('hello');
// -> -1
If you want to keep using the Array.prototype.include() in javascript you can use this script:
Github-script-ie-include
That converts automatically the include() to the match() function if it detects IE.
if (!String.prototype.includes) {//To check browser supports or not
String.prototype.includes = function (str) {//If not supported, then define the method
return this.indexOf(str) !== -1;
}
}
console.log("abcde".includes("cd"));