Home >Web Front-end >JS Tutorial >Js remove spaces in string (implementation code)_javascript skills
1. Remove the spaces at both ends of the string
String.prototype.trim=function (){return this.replace(/(^/s*)|(/s*$)/g,'');}
2. Remove all spaces in the string:
String.prototype.sTrim = function (){return this.replace(//s/g, ''); }
or:
var s = "asd ddd bbb sss";
var reg = //s/g;
var ss = s.replace(reg, "");
alert(ss);