Home > Web Front-end > JS Tutorial > Two methods of javascript customizing startWith() and endWith()_javascript skills

Two methods of javascript customizing startWith() and endWith()_javascript skills

WBOY
Release: 2016-05-16 17:16:12
Original
1730 people have browsed it

1. Use regular expressions to implement startWith and endWith effect functions

Copy code The code is as follows:

String.prototype.startWith=function(str){
var reg=new RegExp("^" str);
return reg.test(this);
}
//Test ok, directly Just use str.endWith("abc") to call
String.prototype.endWith=function(str){
var reg=new RegExp(str "$");
return reg.test( this);
}

2. JavaScript implements startWith and endWith effect functions
Copy code The code is as follows:

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template