How do I replace all occurrences of a string in javascript? I've tried the following code:
string.replaceAll('aa', 'b')
but it doesn't seem to have worked
How do I replace all occurrences of a string in javascript? I've tried the following code:
string.replaceAll('aa', 'b')
but it doesn't seem to have worked
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');