Dark Launch

JavaScript startsWith function string, characters

JavaScript starts with a string.

Javascript
function startsWith(data, input) {
    return data.substring(0, input.length) === input;
}
 
String.prototype.startsWith = function (input) {
    return this.substring(0, input.length) === input;
};
Javascript
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);

Comments


  1. good