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

JavaScript: IE11 String.startsWith() Prototype/Function

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

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


if (!String.prototype.startsWith) {
    String.prototype.startsWith = function (text) {
        return this.lastIndexOf(text, 0) == 0;
    };
}

Using the above code snippet:


if (!String.prototype.startsWith) {
    String.prototype.startsWith = function (text) {
        return this.lastIndexOf(text, 0) == 0;
    };
}
alert("this is a test".startsWith("this"));

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