Home > Web Front-end > JS Tutorial > body text

How to remove all spaces in a string using javascript_javascript tips

WBOY
Release: 2016-05-16 19:19:21
Original
996 people have browsed it

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);
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template