Global context being affected by array function .replace

This is because you are handling a pointer to the context variable and not a copy so this will effect the origin.
You will need to clone the variable to manipulate it without doing it.
Fortunately Nodered has a deep cloning function build into to the function nodes by default. Its documented here:

https://nodered.org/docs/api/modules/v/0.20.0/@node-red_util_util.html#.cloneMessage
Edit:
Forgot an example.
It can be accessed in a function node by using something like this:

var origin = global.get("origin");
var copy =  RED.util.cloneMessage(origin);
1 Like