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);
1 comment
good
Leave a Reply