String.prototype.includes
is, as you write, not supported in Internet Explorer (or Opera).
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
MDN has a polyfill for includes
using indexOf
: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill
EDIT: Opera supports includes
as of version 28.
EDIT 2: Current versions of Edge supports the method. (as of 2019)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…