Skip to content
𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

Fix for Javascript String.includes not supported by IE

Posted on July 11, 2018December 10, 2023 By sastrija

IE doesn’t support some of the String methods which is available with other browsers. String.includes is one of them. One of the simple solution is to define its prototype as below.

if(!String.prototype.includes) { // Set prototype only if it is not supported
  String.prototype.includes = function (str) {
    return this.indexOf(str) !== -1
  }
}

Just add above javascript code in to a javascript file (Definitely it should execute before you call String.includes in your code) to fix this issue.

Another solution is to use indexOf instead of includes.

Related

JavaScript JavaScriptPlugins

Post navigation

Previous post
Next post
©2025 𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ | WordPress Theme by SuperbThemes