How can I replace space with another string in JavaScript? -


i have code:

var str = '                  abc'; str.replace(" ",""); 

but not working.

first, have spelling error:

replce 

you should do:

var str = ' abc'; str = str.replace(/ /g,""); 

the /g global modifier replace specified text throughout given string.


alternatively, can use split , join this:

var str = ' abc'; str = str.split(" ").join(""); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -