88
rated 0 times
[
94]
[
6]
/ answers: 1 / hits: 173134
/ 8 Years ago, tue, april 12, 2016, 12:00:00
This code does not work in internet explorer. Any alternative?
abcde.includes(cd)
More From » javascript
This code does not work in internet explorer. Any alternative?
abcde.includes(cd)
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)