How can I use a variable to remove all instances of a substring from a string? (to remove, I\'m thinking the best way is to replace, with nothing, globally... right?)
Well, you can use this:
var reg = new RegExp(oldWord, "g"); myString.replace(reg, "");
or simply:
myString.replace(new RegExp(oldWord, "g"), "");