How to replace all occurrences of a string in JavaScript? I have this string: "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? Answer: For the sake of completeness, I got to thinking about which method I should use to do this. There are basically two ways to do this as suggested by the other answers on this