Home >Web Front-end >JS Tutorial >Add a method to remove left and right spaces for String objects in Javascript (sample code)_javascript skills
looks like this:
String.prototype.trim=function(){
var m=this.match(/^s*(S (s S )*)s*$/);
return (m==null )?"":m[1];
}
Use:
var message =" I'm fine ";
message.trim();