PROWAREtech

articles » current » javascript » ie11-prototype-string-endswith

JavaScript: IE11 String.endsWith() Prototype/Function

Create the String.endsWith() prototype for Internet Explorer 11.

Still developing for IE11? Well, this prototype returns true when the string ends with the argument.


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

Using the above code snippet:


if (!String.prototype.endsWith) {
    String.prototype.endsWith = function (text) {
        return this.indexOf(text, this.length - text.length) != -1;
    };
}
alert("this is a test".endsWith("test"));

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
CLOSE