9
When I want to replace all occurrences of a string I do so:
var ola= "ola mundo ola mundo";
ola = ola.replace(/ola/g, "xxx");
Result: "xxx world xxx world";
But I want to use a variable instead of putting the word explicitly, in this way:
var ola= "ola mundo ola mundo";
var variavel= "ola";
ola = ola.replace(/variavel/g, "xxx");
I just don’t know how to concatenate it to work. I’ve tried it in some ways and it didn’t work.