startsWith and endsWith functions in Javascript
startsWith and endsWith functions in Javascript
inside the Javascript tag,
startsWith to check if a string starts with a particular character sequecnce:
var data = “Helloo Good Morning”;
startsWith
String.prototype.startsWith = function(data)
{
return (this.match(“^”+data)==data)
}
eg:
data.startsWith(“Helloo”);
returns true
endsWith Function
endsWith to check if a string ends with a particular character sequecnce:
String.prototype.endsWith = function(data)
{
return (this.match(data+”$”)==data)
}
eg:
data.endsWith(“Helloo”);
returns false;


