Home  >  Article  >  Web Front-end  >  Add a method to remove left and right spaces for String objects in Javascript (sample code)_javascript skills

Add a method to remove left and right spaces for String objects in Javascript (sample code)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:11:331226browse

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();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn