Thursday, December 18, 2008 1:37 PM
Alright, so for the .NET developers, if you don't already know the .Replace JavaScript function does not work like the String.Replace function in .NET, in .NET, it replaces all occurrences while in JavaScript it only replaces the first instance.
"H e l l o W o r l d".replace(' ','');
will return "He l l o W o r l d" - notice the rest of the spaces weren't removed.
The easiest solution to the problem, assuming you want to replace all spaces in the string is to use regular expression.
"H e l l o W o r l d".replace(/\s/g,'');
The above will or should return "HelloWorld" with no spaces in the string.