Home  >  Article  >  Web Front-end  >  Summary of javascript methods for removing spaces_javascript skills

Summary of javascript methods for removing spaces_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:58:031243browse

The example in this article summarizes the JavaScript method of removing spaces. Share it with everyone for your reference. The details are as follows:

Here str is the string to remove spaces:

Remove all spaces:

Copy code The code is as follows:
str = str.replace(/s /g,"");

Remove double spaces:

Copy code The code is as follows:
str = str.replace(/^s s $/g,"");

Remove left space:

Copy code The code is as follows:
str=str.replace( /^s*/, '');

Remove right space:

Copy code The code is as follows:
str=str.replace(/(s*$)/g, "") ;

I hope this article will be helpful to everyone’s JavaScript programming design.

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