//Uses the substring function
//Checks from the start of the string to the
//d.length number of characters
String.prototype.startsWith = function (d) {
var first = this.substr(0,d.length);
if(d===first){
return true;
}else{
return false;
}
};
//Uses the substing functio
//Checks d.length number of characters from the end
String.prototype.endsWith = function (d) {
var startIndex = this.length - d.length;
if(startIndex>0){
var last = this.substr(startIndex,d.length );
if(d===last){
return true;
}else{
return false;
}
}else{
return false;
}
};
/*
var toCheck = "hang the dj";
alert(toCheck.startsWith("hang"));
alert(toCheck.startsWith("Hang"));
alert(toCheck.startsWith("I’ve got a room for rent"));
alert(toCheck.startsWith(""));
alert(toCheck.startsWith("hang the"));
alert(toCheck.startsWith("42"));
alert(toCheck.startsWith("{ first: “Johnny” }"));
alert(toCheck.endsWith("dj"));
alert(toCheck.endsWith("panic on the streets"));
alert(toCheck.endsWith(""));
alert(toCheck.endsWith("the dj"));
alert(toCheck.endsWith("42"));
alert(toCheck.endsWith("{ first: “Johnny” }"));
*/
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.