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,411
  • 5
  • 24
  • 65

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
  • 1,031,962
  • 187
  • 1,923
  • 1,875