I have found plenty of questions that almost answer my question, for example this myString.replace( VARIABLE, "") ...... but globally but they all lack one detail.
I want to do something like this
var clipText = "aaabccc";
var replaceStr = "abc";
var withStr = "def";
clipText = clipText.replace(/replaceStr/g, withStr);
That is, use two variables as arguments to replace
but replace
seems to interpret the variable names literally rather than using their assigned value. I also want to replace all occurrences, hence the g
after replaceStr
.
What gives?