JavaScript startsWith function string, characters

JavaScript starts with a string.

function startsWith(data, input) {
    return data.substring(0, input.length) === input;
}
 
String.prototype.startsWith = function (input) {
    return this.substring(0, input.length) === input;
};
var url = "https://www.example.com/";
 
console.assert(url.startsWith("https://") === true);
console.assert(url.startsWith("http://") === false);
console.assert(startsWith(url, "https://") === true);
console.assert(startsWith(url, "http://") === false);
Did this help you? Please let me know with a comment. Thank you
Posted .

1 comment (RSS)

  1. anonymous

    good

Leave a comment