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?)
<
No need to use a regular expression here: split the string around matches of the substring you want to remove, then join the remaining parts together:
myString.split(oldWord).join('')
In the OP's example:
var myString = "This sentence is an example sentence.";
var oldWord = " sentence";
console.log(myString.split(oldWord).join(''));