[wd_asp elements=’search’ ratio=’100%’ id=1]

String replace – Remove spaces / whitespace Javascript

21st November 2013

Javascript

javascript category codehaven

var string = "+hello this is text";
string = string.replace(' ','');//no spaces
string = string.replace('+',''); //no + sign
alert(string);

Replace whitespace (alternative if above does not work) This works for integers unlike above.

label = label.replace(/\s/g, "");