if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str){
return this.slice(0, str.length) == str;
};
}
if (typeof String.prototype.endsWith != 'function') {
String.prototype.endsWith = function (str){
return this.slice(-str.length) == str;
};
}
Then use it:"Starts with JavaScript".startsWith("Starts"); // true
var foo= "Ends with JavaScript";
var bar= "JavaScript";
foo.startsWith(bar); // true