Home  >  Article  >  Web Front-end  >  How to remove all spaces in a string using javascript_javascript tips

How to remove all spaces in a string using javascript_javascript tips

WBOY
WBOYOriginal
2016-05-16 19:19:21994browse

This seems to only remove 2 spaces

Copy code The code is as follows:

String.prototype .trim=function (){return this.replace(/(^s*)|(s*$)/g,'');}

Method 1:
Copy code The code is as follows:

String.prototype.mm = function (){return this.replace(/s/ g, '');}

Method 2:

Copy code The code is as follows :

var s = "asd ddd bbb sss";
var reg = /s/g;
var ss = s.replace(reg, "");
alert(ss);
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