1

I have the following code using the javascript replace but not all instances are being replaced:

var str = '9c88a4f84d6b0c94-3e8a-ca0a320c6509';
str = str.replace("-", ""); 
alert(str);

What am I missing?

mpora
  • 1,329
  • 3
  • 22
  • 55

1 Answers1

3

It's replacing the first one. That's what it does when you give it a string. To replace all of them, use a regular expression with the g flag:

str = str.replace(/-/g, "");
T.J. Crowder
  • 959,406
  • 173
  • 1,780
  • 1,769