JavaScript endsWith is not working in IEv10?

endswith is not a function
javascript endswith mdn
js endswith ie11
js regex ends with
uri endswith
endswith alternative
window location pathname endswith
str endswith

I'm trying to compare two strings in JavaScript using endsWith(), like

var isValid = string1.endsWith(string2);

It's working fine in Google Chrome and Mozilla. When comes to IE it's throwing a console error as follows

SCRIPT438: Object doesn't support property or method 'endsWith' 

How can I resolve it?

Method endsWith() not supported in IE. Check browser compatibility here.

You can use polyfill option taken from MDN documentation:

if (!String.prototype.endsWith) {
  String.prototype.endsWith = function(searchString, position) {
      var subjectString = this.toString();
      if (typeof position !== 'number' || !isFinite(position) 
          || Math.floor(position) !== position || position > subjectString.length) {
        position = subjectString.length;
      position -= searchString.length;
      var lastIndex = subjectString.indexOf(searchString, position);
      return lastIndex !== -1 && lastIndex === position;

JavaScript String endsWith() Method, JavaScript String endsWith() Method - Fixing error "Object doesn't support property or endsWith” is available or not and if it is not available it will provide custom Specialises in problem identification and proposal of alternative solutions. ‘dont provide alternatives’ you should use endsWith with the polyfill - then when IE dies you can delete the polyfill rather than having to rewrite the code to use the correct method.

I found the simplest answer,

All you need do is to define the prototype

 if (!String.prototype.endsWith) {
   String.prototype.endsWith = function(suffix) {
     return this.indexOf(suffix, this.length - suffix.length) !== -1;

endsWith issue in IE11 - JavaScript, EndsWith" polyfill. but I have no idea how to implement t… anyone help me how to implement the prototype with the below code to work in ie. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more JavaScript endsWith is not working in IEv10?

It's generally bad practise to extend the prototype of a native JavaScript object. See here - Why is extending native objects a bad practice?

You can use a simple check like this that will work cross-browser:

var isValid = (string1.lastIndexOf(string2) == (string1.length - string2.length))

String.prototype.endsWith(), This method lets you determine whether or not a string ends with another string. This method is case-sensitive. Polyfill. This method has been  Many Internet Web sites contain JavaScript, a scripting programming language that runs on the web browser to make specific features on the web page functional. If JavaScript has been disabled within your browser, the content or the functionality of the web page can be limited or unavailable.

Reaction on an old issue: Elaborating on alternative for endsWith() in IE11.

To avoid that string1 = "a", string2 = "bc"; would return true:

var isValid = (string1.lastIndexOf(string2) == (string1.length - string2.length) && string1.lastIndexOf(string2) >= 0);

User Pranav C Balan, javascript angular typescript dom asked Feb 1 '18 at 6:47 JavaScript iterate key & value from json? JavaScript endsWith is not working in IEv10? The prototype extends the String object so that you can add a function like startsWith. In the startsWith definition code above, we're passing in a string parameter called "str" and inside the function code, we are using the indexOf function to check to see if the string parameter is at the start of the original string by checking to see if the index is zero (first character of the original

‍❤️‍ Send notification automatically from Firebase, Firebase provides push notification, but not changes to the database table. What you can do, you can create listeners in the background and issue a notification  This JavaScript tutorial explains how to use the string method called endsWith() with syntax and examples. In JavaScript, endsWith() is a string method that is used to determine whether a string ends with a specific sequence of characters.

‍ Open iCloud Drive in iOS app, Firebase provides push notification, but not changes to the database table. What you can do, you can create listeners in the background and issue a notification  The endsWith() method determines whether a string ends with the characters of a specified string, returning true or false as appropriate.

JavaScript String endsWith() Method, This method returns true if the string ends with the characters, and false if not. Note: The endsWith() method is case sensitive. Browser Support. Method. Am aflat aceasta pagina, dupa ce am cautat despre Array.indexOf in JavaScript not working in IE pe Google. Se pare ca informatia dvs e foarte valoroasa, mai ales ca am mai gasit aici si despre ie fix, ora exacta, lucruri interesante si folositoare. Mult succes in continuare!

  • It helps to know that this script can be placed anywhere. Ideally it is loaded as the page loads too so that it is made available to all other functions
  • Find the simplified answer here…
  • This will fail basic test cases e.g string1 = "a", string2 = "bc"; would return true