How do I replace all occurrences of a string in JavaScript? I tried:
string.replaceAll('aa', 'b')
How do I replace all occurrences of a string in JavaScript? I tried:
string.replaceAll('aa', 'b')
If you use a regex with the g flag you can replace all instances in one replace call.
var str = ...;
var regex = /aa/g;
str.replace(regex, 'b');