Data from Multiple Arrays to a single Array

I'm try to merge data from the multiple arrays into a single array, but I'm unable debug the data. Can someone provide any suggestions.

Thank you


Hi @mjbhuyan

That screenshot alone does not give us enough information to help.

Can you provide an example of the arrays you have and what you would want the result to look like?

1 Like

Mate you need to post your code not just screenshots. We can't copy/edit/paste and I'm certainly not about to re-type from a screenshot.

I suggest you put a real sample data into an inject node connected to your function node with your code in and post that with an example of how you want the data to look and how you want it to appear in the output.

Thanks for the reply. I'm try to get the output as an array of all "fields1" in (from 1 to 28) in a new Single array. Somewhat like - [48.8 , ..., 45.7, ...]

As @Steve-Mcl has said, if you can provide a sample of the input data that would make it much easier. The structure you are starting with is quite complicated and you'd save us a lot of work if you provided real data we could copy.

From what I can see, I think if you pass that message through a Change node, configured to set msg.payload to the expression:


You'll get what you've asked for.

1 Like

Data Source-

Function code -

var pay = msg.payload;
var outputMsgs =[];
for (var n=0; n<28; n++)
var data=Number(pay.feeds[n].field1);
var myVars = data;
return [outputMsgs ];

Clipboard -

[{"id":"a6132ac7.081118","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"3f474fb7.8182d","type":"inject","z":"a6132ac7.081118","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":80,"wires":[["b5f30778.720628"]]},{"id":"b5f30778.720628","type":"http request","z":"a6132ac7.081118","name":"","method":"GET","ret":"txt","url":"","tls":"","x":310,"y":120,"wires":[["856719a7.783b68"]]},{"id":"8fc78409.522328","type":"debug","z":"a6132ac7.081118","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":180,"wires":[]},{"id":"856719a7.783b68","type":"json","z":"a6132ac7.081118","name":"","property":"payload","action":"","pretty":false,"x":360,"y":300,"wires":[["a710d00f.f6ac5"]]},{"id":"58f01f1f.3b823","type":"function","z":"a6132ac7.081118","name":"","func":"\nvar pay = msg.payload;\n\nvar outputMsgs =;\n\nfor (var n=0; n<28; n++)\n{ \n \n var data=(pay.feeds[n].field1);\n \n var myVars = data;\n \n outputMsgs.push(myVars); \n\n}\n\nreturn [outputMsgs ];\n\n","outputs":1,"noerr":0,"x":540,"y":160,"wires":[["8fc78409.522328"]]},{"id":"19fa08e.79b33f7","type":"file in","z":"a6132ac7.081118","name":"","filename":"/home/user/Desktop/Humidity","format":"utf8","chunk":false,"sendError":false,"x":780,"y":100,"wires":[]},{"id":"a710d00f.f6ac5","type":"change","z":"a6132ac7.081118","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.feeds.field1","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":400,"wires":[["58f01f1f.3b823"]]},{"id":"be66668d.bd4588","type":"function","z":"a6132ac7.081118","name":"Humidity","func":"var all=0;\nfor (var n=0; n<28; n++)\n{ \n var data = Number(msg.payload.feeds[n].field1);\n var all= all+ data;\n}\nmsg.payload = all/28;\nreturn msg;\n","outputs":1,"noerr":0,"x":700,"y":280,"wires":[]}]

I tried that, but it seems not to be working.

Please read this post about how to properly format flows and code

That's a shame. I'm sure if you share a bit more detail about what did happen then we might be able to help. Just saying it doesn't work does not give us anything to work with.

Took a look at your flow.

You have configured the Change node to set it to an Environment Variable - that is wrong. It should be the Expression type. (Make sure you add the $. back to the front of the expression when you fix it).

You then have that Change node wired to your Function node that has your attempt at pulling out the values into an array. That won't work because the Change node has already done it.

Fix the Change node and remove the Function node.

Thank you very much @knolleary for your quick help. I'm quite new to this, so I prompt to make silly mistakes. But, your suggestion worked for me to get the desired output.