I have searched long and far for a way to have a function change a given global variable using the function's arguments and local variables inside as the "shortcut" to it. Because I can't find the right words to explain this well, I will be adding 2 scripts bellow, the first being what it looks like and the second being what it should act like.
Note: The examples given are meant to replace all matching characters/text of a location to a new value.
Example 1:
function ReplaceAll(loc,old,new_text) {
while (loc.includes(old)) {
var new1 = loc.replace(old,new_text);
}
loc = new1;
}
This script [Example 1] is how I wish to set up my script yet it does not work because it only catches the value of the location and not setting the original value when changed.
Example 2:
var example = "What is? Where is? Why is? Who is?";
ReplaceAll(example,"is","was");
console.log(example);
Preferred Output: "What was? Where was? Why was? Who was?"
This script [Example 2] is the effect that I am attempting to achieve to be able to make this and other scripts of mine work.
PS: I am not trying to ask for people to do the work for me thus going against the rules of Stack Overflow, I just want to know, if possible, how this can be done.
Thank you.