views:

67

answers:

3

I have the string R.E.M. and I need to make it REM

So far, I have:

$('#request_artist').val().replace(".", "");

...but I get RE.M.

Any ideas?

+3  A: 

You could pass a regular expression to the replace method and indicate that it should replace all occurrences like this: $('#request_artist').val().replace(/\./g, '');

Darin Dimitrov
+5  A: 

The first argument to replace() is usually a regular expression.

Use the global modifier:

$('#request_artist').val().replace(/\./g, "");

replace() at MDC

Pekka
+2  A: 

The method used to replace the string is not recursive, meaning once it found a matching char or string, it stop looking. U should use a regular expression replace.

$("#request_artist").val().replace(/\./g, '');

Check out Javascript replace tutorial for more info.

joshuafreelance