JavaScript uses regular expressions to implement startWith and endWith effect functions
String.prototype.startWith=function(str){
var reg=new RegExp("^" str);
return reg.test(this);
}
String .prototype.endWith=function(str){
var reg=new RegExp(str "$");
return reg.test(this);
}
JavaScript Implement startWith and endWith effect functions
//The following is an example of usage
var url = location.href;
if (url.startWith('http:// www.jb51.net'))
{
//If the current url starts with http://www.jb51.net/
}
Another one is It is implemented using indexOf:
var index = str.indexOf( 'abc');
if(index==0){
//Start with 'abc'
}