I have come across many similar questions that almost address my query, such as this example about replacing a string globally but they all seem to miss one important detail.
I am trying to achieve something along the lines of:
var clipText = "aaabccc";
var replaceStr = "abc";
var withStr = "def";
clipText = clipText.replace(/replaceStr/g, withStr);
Essentially, I want to pass two variables as arguments to the replace
function. However, it appears that replace
is interpreting the variable names literally rather than using their actual values. Additionally, I aim to replace all occurrences of the specified string, hence the inclusion of g
after replaceStr
.
What could be causing this issue?