You do not assign the result of the replacement method back to your variable. When you call replace, it returns a new line without changing the old one.
For example, download this into your favorite browser:
<html><head></head><body> <script type="text/javascript"> var str1 = "a,d,k"; str1.replace(/\,/g,""); var str2 = str1.replace(/\,/g,""); alert (str1); alert (str2); </script> </body></html>
In this case, str1 will still be "a,d,k" , and str2 will be "adk" .
If you want to change str1 , you should do:
var str1 = "a,d,k"; str1 = str1.replace (/,/g, "");
Bob May 26 '09 at 1:53 a.m. 2009-05-26 01:53
source share