Changing Data without changing Variable

Hello,

I have got a problem with global variables.
The global variable changes its value even when I don't apply global.set(). How does it come and how can I prevent it. It looks like the variable in the flow is still connected to the global one.

I built a little flow for the demonstration but I cant upload a file.

[{"id":"dc859282.3c8a7","type":"inject","z":"dd2b1b78.857558","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":600,"y":160,"wires":[["f842a5f3.e01728"]]},{"id":"f842a5f3.e01728","type":"function","z":"dd2b1b78.857558","name":"set global Obj","func":"var global_obj = {\n \"array_1\" : [1,2,3],\n \"array_2\" : [4,5,6],\n \"array_3\" : [[1,2,3] , [7,null,9], [4,5,6]],\n};\n\nglobal.set(\"global_obj\", global_obj);\nreturn msg;","outputs":1,"noerr":0,"x":810,"y":160,"wires":[["11d65e6b.112022"]]},{"id":"11d65e6b.112022","type":"debug","z":"dd2b1b78.857558","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1010,"y":160,"wires":[]},{"id":"35096b3b.a84954","type":"inject","z":"dd2b1b78.857558","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":600,"y":240,"wires":[["7c2be196.5bb1"]]},{"id":"7c2be196.5bb1","type":"function","z":"dd2b1b78.857558","name":"Replace null","func":"var data_ist = global.get(\"global_obj\").array_3[1];\n\nfor (let i in data_ist){\n if (data_ist[i] ===null){\n if (i >= 1){\n if (data_ist[(i-1)] !== null){\n var lower_value = data_ist[i-1];\n data_ist[i] = lower_value ;\n }\n \n }\n }\n}\nmsg.payload = data_ist;\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":240,"wires":[["b71d41f5.a5bf6"]]},{"id":"b71d41f5.a5bf6","type":"debug","z":"dd2b1b78.857558","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1010,"y":240,"wires":[]}]

Thanks for your help.

Thomas

This is because of the way JavaScript passes objects around by reference...

This previous thread explains the details and how to handle it - Global memory updates even if I don't "save" back to it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.