I am a noob when it comes to programming, See me as a Frankenstein coder.
The data stored in flow data =
[
{"ps":"previous state","type":"1","hold":"0","count":0,"name":"name","resrv":0},
{"ps":false,"type":0,"hold":0,"count":0,"name":"name","resrv":0},
{"ps":false,"type":0,"hold":0,"count":0,"name":"name","resrv":0}
.... and some more of the same]
If i run the following code
var y = flow.get('data') || 0;
y[1].name = "this";
//flow.set('data',y);
msg.test = flow.get('data['+1+'].name');
return msg;
the output is - test: "this" where it should be "name"
and it is stored in flow data.
But when I try this with Steve’s Internet Guide -- Storing Data in Node-Red Variables
(the function is edit by me)
//var count=context.get('count') || 0;
var count = flow.get('count') || 0;
count = 8;
msg.payload=flow.get('count');
//flow.set('count',count);
return msg;
it will not set the flow variable.
is it because of the variable type array of objects and the reference to it
please explain thanks
edit added the flow
[{"id":"2b25bfd6.19345","type":"function","z":"3666b531.e1652a","name":"","func":"\nvar y = flow.get('data') || 0;\n\ny[1].name = \"this\";\n//flow.set('data',y);\n\nmsg.test = flow.get('data['+1+'].name')\n\nvar i =2;\n//flow.set('data['+i+'].name',\"ikke\")\n\nreturn msg;\n\n\n","outputs":1,"noerr":0,"x":490,"y":260,"wires":[["b005f2d3.2bc1e"]]},{"id":"f24dc261.54a55","type":"inject","z":"3666b531.e1652a","name":"Items list","topic":"","payload":"[{\"ps\":\"previous state\",\"type\":\"1,2,3,4,5,6\",\"hold\":\"0,1,2\",\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0},{\"ps\":false,\"type\":0,\"hold\":0,\"count\":0,\"name\":\"name\",\"resrv\":0}]","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":200,"y":260,"wires":[["5375937e.8dc7ec"]]},{"id":"b005f2d3.2bc1e","type":"debug","z":"3666b531.e1652a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":260,"wires":[]},{"id":"5375937e.8dc7ec","type":"function","z":"3666b531.e1652a","name":"","func":"var test=flow.get('data') || 0;\n\nif (test ===0){\n flow.set('data',msg.payload);\n}\nmsg.payload = \"\";\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":260,"wires":[["2b25bfd6.19345"]]}]