Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  94] [ 6]  / answers: 1 / hits: 173133  / 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

 Answers
4

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)


[#62595] Monday, April 11, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
margaritakristinak

Total Points: 502
Total Questions: 127
Total Answers: 98

Location: England
Member since Mon, May 17, 2021
3 Years ago
;