How to replace all occurrences of a string in JavaScript
Asked 07 September, 2021
Viewed 2.6K times
  • 54
Votes

I have this string in my JavaScript code:

"Test abc test test abc test test test abc test test abc"

Doing:

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

Seems to only remove the first occurrence of abc in the string above.

How can I replace all occurrences of it?

30 Answer