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