Thursday, November 23rd, 2017

startsWith and endsWith functions in Javascript

0

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;

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • RSS
  • Technorati
  • Twitter

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Secure Linux Web Hosting