When I want to do a replace on all occurrences of a string I do this:
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 explicit, like this:
var ola= "ola mundo ola mundo"; var variavel= "ola"; ola = ola.replace(/variavel/g, "xxx");
I just do not know how to concatenate this to work. I've tried it in some ways and it did not work.