Function with two outputs

The spread operator will not do a deep clone so this will only work if your object you are cloning is only one layer deep.
Node-red actually provides cloning functionality in the form of

var newMsg = RED.util.cloneMessage(msg))

which uses one of the available npm modules for cloning.
You can also use the hackish way which is:

var newMsg = JSON.parse(JSON.stringify(msg))

Johannes

Edit:
You can read more about it here


Dont know if the nodered functionality isnt also based on lodash which is mentioned in this article.
1 Like