Make an ARRAY after a text input node.

Hi, I'm a lost beginner.
Want to join 14 text input node to an ARRAY to send to an S7 PLC.
ARRAY should be updated immediately when any of the text input node is updated.

ARRAY looks like this:

{"signal":"Av-restid","path":"DB4,DWORD26..13","error":0,"value":[0,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000]}

[{"id":"4baf23af.ed80f4","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"495d4970.0c4c6","type":"s7comm read","z":"4baf23af.ed80f4","connection":"e971ffef.8d56b8","payload":"{\"S7_Type\":\"DB\",\"S7_DBnum\":\"4\",\"S7_Datatype\":\"D\",\"S7_Offset\":\"26\",\"S7_BitOffset\":\"0\",\"S7_Quantity\":\"14\",\"S7_Name\":\"Av-restid\"}","s7Name":"Av-restid","topic":"","name":"","signalSetted":false,"none":"false","repeat":"7","once":true,"x":85,"y":200,"wires":[["f11c0d23.979ec8","9f44a39.f764c6","95388777.87a83","76eec174.a1b018","f977e8ce.f98c","dacf6b0b.ecb35","daced7d3.c9b27","b3106292.086a6","8783fff0.36791","31f1a15e.99567e","627c9bc5.1bae9c","a642ed10.df5658","bdb27c88.91ea98","764c9d45.7dc9a4"]]},{"id":"30d511f9.c94e56","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[0]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":312.5,"y":270,"wires":[["d5f1c400.c5d618"]]},{"id":"d5f1c400.c5d618","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Måndag tid 1","tooltip":"","group":"38e6ec70.739054","order":2,"width":6,"height":1,"passthru":false,"mode":"time","delay":"100","topic":"1","x":500,"y":270,"wires":[["28c0da12.6312a6"]]},{"id":"d94dd544.9faee","type":"s7comm write","z":"4baf23af.ed80f4","connection":"e971ffef.8d56b8","payload":"{\"S7_Type\":\"DB\",\"S7_DBnum\":\"4\",\"S7_Datatype\":\"D\",\"S7_Offset\":\"26\",\"S7_BitOffset\":\"0\",\"S7_Quantity\":\"14\",\"S7_Name\":\"Av-restid\"}","s7Name":"Av-restid","topic":"","name":"","signalSetted":false,"x":1051.5,"y":206,"wires":[["7a62e813.04bf7"]]},{"id":"e72ea8ec.7de7","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":853.5,"y":266,"wires":[["7a62e813.04bf7","d94dd544.9faee"]]},{"id":"f11c0d23.979ec8","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[1]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":307,"y":322,"wires":[["71e2995c.7dc9c"]]},{"id":"71e2995c.7dc9c","type":"ui_text_input","z":"4baf23af.ed80f4","name":"Måndag tid 2","label":"Måndag tid 2","tooltip":"","group":"38e6ec70.739054","order":3,"width":6,"height":1,"passthru":false,"mode":"time","delay":"100","topic":"2","x":491.5,"y":321,"wires":[["28c0da12.6312a6"]]},{"id":"166e9c34.f71294","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":851,"y":320,"wires":[[]]},{"id":"9f44a39.f764c6","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[2]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":305,"y":367,"wires":[["cc65950e.de7d"]]},{"id":"cc65950e.de7d","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Tisdag tid 1","tooltip":"","group":"38e6ec70.739054","order":4,"width":6,"height":1,"passthru":false,"mode":"time","delay":"100","topic":"3","x":489.5,"y":366,"wires":[["28c0da12.6312a6"]]},{"id":"fc82fc40.25b0c8","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":849,"y":365,"wires":[[]]},{"id":"95388777.87a83","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[3]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":303,"y":413,"wires":[["7940281c.dd6058"]]},{"id":"7940281c.dd6058","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Tisdag tid 2","tooltip":"","group":"38e6ec70.739054","order":5,"width":6,"height":1,"passthru":false,"mode":"time","delay":"100","topic":"4","x":487.5,"y":412,"wires":[["28c0da12.6312a6"]]},{"id":"bfa2a6ee.0d8df","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":847,"y":411,"wires":[[]]},{"id":"76eec174.a1b018","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[4]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":306,"y":455,"wires":[["42cd5cbe.35c94c"]]},{"id":"42cd5cbe.35c94c","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Onsdag tid 1","tooltip":"","group":"38e6ec70.739054","order":6,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":490.5,"y":454,"wires":[[]]},{"id":"af8784d8.9da1a","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":850,"y":453,"wires":[[]]},{"id":"f977e8ce.f98c","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[5]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":306,"y":492,"wires":[["dddc84d4.2c7818"]]},{"id":"dddc84d4.2c7818","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Onsdag tid 2","tooltip":"","group":"38e6ec70.739054","order":7,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":491.5,"y":491,"wires":[[]]},{"id":"fa5c9c20.c5986","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":851,"y":490,"wires":[[]]},{"id":"dacf6b0b.ecb35","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[6]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":304,"y":534,"wires":[["d047835c.c53e08"]]},{"id":"d047835c.c53e08","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Torsdag tid 1","tooltip":"","group":"38e6ec70.739054","order":8,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":488.5,"y":533,"wires":[[]]},{"id":"d3e602c4.aa8f","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":848,"y":532,"wires":[[]]},{"id":"daced7d3.c9b27","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[7]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":304,"y":571,"wires":[["66ffa3e1.e57664"]]},{"id":"66ffa3e1.e57664","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Torsdag tid 2","tooltip":"","group":"38e6ec70.739054","order":9,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":489.5,"y":570,"wires":[[]]},{"id":"fdbe4ce3.12d4a","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":849,"y":569,"wires":[[]]},{"id":"b3106292.086a6","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[8]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":303,"y":610,"wires":[["65f29c78.bee2ac"]]},{"id":"65f29c78.bee2ac","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Fredag tid 1","tooltip":"","group":"38e6ec70.739054","order":10,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":487.5,"y":609,"wires":[[]]},{"id":"c3e1675c.4625b","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":847,"y":608,"wires":[[]]},{"id":"8783fff0.36791","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[9]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":303,"y":647,"wires":[["10327704.f44bd1"]]},{"id":"10327704.f44bd1","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Fredag  tid 2","tooltip":"","group":"38e6ec70.739054","order":11,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":488.5,"y":646,"wires":[[]]},{"id":"ee1d58f5.d19e78","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":848,"y":645,"wires":[[]]},{"id":"31f1a15e.99567e","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[10]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":301,"y":689,"wires":[["beebce06.67baf8"]]},{"id":"beebce06.67baf8","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Lördag tid 1","tooltip":"","group":"38e6ec70.739054","order":12,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":485.5,"y":688,"wires":[[]]},{"id":"20918187.9e2d16","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":845,"y":687,"wires":[[]]},{"id":"627c9bc5.1bae9c","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[11]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":301,"y":726,"wires":[["7cef45fb.905eac"]]},{"id":"7cef45fb.905eac","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Lördag tid 2","tooltip":"","group":"38e6ec70.739054","order":13,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":486.5,"y":725,"wires":[[]]},{"id":"cb420276.b270e","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":846,"y":724,"wires":[[]]},{"id":"a642ed10.df5658","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[12]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":297,"y":769,"wires":[["749e6bf7.77e004"]]},{"id":"749e6bf7.77e004","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Söndag tid 1","tooltip":"","group":"38e6ec70.739054","order":14,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":481.5,"y":768,"wires":[[]]},{"id":"daf079f0.5ec6","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":841,"y":767,"wires":[[]]},{"id":"bdb27c88.91ea98","type":"moment","z":"4baf23af.ed80f4","name":"","topic":"","input":"payload.value[13]","inputType":"msg","inTz":"Etc/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm","locale":"en_gb","output":"","outputType":"msg","outTz":"Etc/UTC","x":297,"y":806,"wires":[["edccc666.db5418"]]},{"id":"edccc666.db5418","type":"ui_text_input","z":"4baf23af.ed80f4","name":"","label":"Söndag tid 2","tooltip":"","group":"38e6ec70.739054","order":15,"width":6,"height":1,"passthru":false,"mode":"time","delay":"0","topic":"","x":482.5,"y":805,"wires":[[]]},{"id":"4df27d6d.9652ac","type":"function","z":"4baf23af.ed80f4","name":"","func":"var msg_out = {payload:{value:[msg.payload]}};\nreturn msg_out;","outputs":1,"noerr":0,"x":842,"y":804,"wires":[[]]},{"id":"7a62e813.04bf7","type":"debug","z":"4baf23af.ed80f4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1052.5,"y":127,"wires":[]},{"id":"28c0da12.6312a6","type":"debug","z":"4baf23af.ed80f4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":841.5,"y":115,"wires":[]},{"id":"764c9d45.7dc9a4","type":"debug","z":"4baf23af.ed80f4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":698.5,"y":27,"wires":[]},{"id":"e971ffef.8d56b8","type":"s7comm","z":"","ip":"192.168.1.86","port":"102","rack":"0","slot":"2","payload":[{"S7_Type":"DB","S7_DBnum":"5","S7_Datatype":"R","S7_Offset":"0","S7_BitOffset":"0","S7_Quantity":"1","S7_Name":"UteTemprtur"},{"S7_Type":"DB","S7_DBnum":"5","S7_Datatype":"R","S7_Offset":"20","S7_BitOffset":"0","S7_Quantity":"1","S7_Name":"Tanktopp"},{"S7_Type":"DB","S7_DBnum":"4","S7_Datatype":"D","S7_Offset":"26","S7_BitOffset":"0","S7_Quantity":"14","S7_Name":"Av-restid"},{"S7_Type":"DB","S7_DBnum":"4","S7_Datatype":"D","S7_Offset":"26","S7_BitOffset":"0","S7_Quantity":"1","S7_Name":"Av-Restidwrite"}]},{"id":"38e6ec70.739054","type":"ui_group","z":"","name":"Default","tab":"a4dc9bca.e6c778","order":2,"disp":true,"width":"6","collapse":false},{"id":"a4dc9bca.e6c778","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

You can easily create and add to an array in javascript within a function node, a quick google will find lots of tutorials to show you how.

What I do not understand is how to see the difference in the received Payload from text input. Have read something about "Topic" but do not understand.

Add a debug node after your text input node and give us an example...

Uses this code to send single value. Not to an ARRAY.

var msg_out = {payload:{value:[msg.payload]}};
return msg_out;

2019-10-03 12:18:19node: 28c0da12.6312a6
1 : msg.payload : number
25200000
2019-10-03 12:18:19node: 28c0da12.6312a6
1 : msg.payload : number
27600000
2019-10-03 12:18:26node: 28c0da12.6312a6
3 : msg.payload : number
16800000
2019-10-03 12:18:26node: 28c0da12.6312a6
3 : msg.payload : number
14700000
2019-10-03 12:18:26node: 28c0da12.6312a6
3 : msg.payload : number
17400000

It would be more useful to give us an example of the message you are sending to your function node rather than examples of what you know doesn't work.

Assuming all your data is in the one message going into your function, you will need to create the array and push the data into that array before you return it
https://www.w3schools.com/jsref/jsref_push.asp

How do I implement that TOPIC determines the location in ARRAY.

In the debug , the value of TOPIC is: 1 and 3

ARRAY looks like this:

{"signal":"Av-restid","path":"DB4,DWORD26..13","error":0,"value":[0,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000,27600000]}

Lets take a step back.
You are taking one message splitting it into 14 messages.
Do you need to merge the 14 messages back into 1 message? If so look at the join node

Given there are 14 values in your array I'm not sure how you could use 1 or 3 to define all the positions in the array. But you can define the position in an array using splice
https://www.w3schools.com/jsref/jsref_splice.asp

Do you need to merge the 14 messages back into 1 message?Yes

How should I be able to tell which text input node Payload is sent from?

Take a look at the config panel for your text nodes where you can specify a topic.

Where should TOPIC be placed?

var msg_out = {payload:{value:[*topic.1*][msg.payload]}};
 return msg_out;

In the box labelled “Topic” ?

Where should "Topic" be placed in the code.

var msg_out = {payload:{value:[topic.1][msg.payload]}}; return msg_out;

{topic:'thisisthetopic',payload:'thisisthepayload'}

Have a look at the node red docs. There is a section on working with messages that you may find useful. Also look at the rest of the docs of course.

Feature I'm trying to create:
Topic = 1 move payload to array place 1
Topic = 2 move payload to array place 2
Etc

The code below does not work. Just to try to explain


If (msg.topic==1) {
    var msg1 = msg.payload;
}

If (msg.topic==2) {
    var msg2 = msg.payload;
}
If (msg.topic==3) {
    var msg3 = msg.payload;
}
If (msg.topic==4) {
    var msg4 = msg.payload;
}



var array= {payload:[msg1, msg2, msg3 , msg4]}


return array;

It is not a good idea to use variables starting with msg as simple variables, keep names like that for messages, it will avoid confusion in the future. Also consider whether the topic is a string or a number, if it is a string then you need to compare against "1". Finally, what do you think the values of msg2, 3 and 4 that you are putting into the array will be when you get a topic of 1?
I suspect you may want to feed all your input messages into a Join node set to generate key/value pairs before passing that on to a function node. Alternatively look in the node-red doc on writing functions. In particular the section where it talks about using node context to save information so that data from previous messages is made available in the function.

Sometimes Node-RED makes it easier for you...

[{"id":"5a193e81.d3d9b8","type":"inject","z":"fde1fdc8.696df","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":140,"wires":[["dfdf77b.4aebe88","2344bf48.e7f348","6c84b3d9.4ee76c","fc97af08.a91658"]]},{"id":"dfdf77b.4aebe88","type":"function","z":"fde1fdc8.696df","name":"Topic 1","func":"msg.topic=\"1\"\nmsg.payload = \"en\"\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":140,"wires":[["f044da86.a607c8"]]},{"id":"2344bf48.e7f348","type":"function","z":"fde1fdc8.696df","name":"Topic 2","func":"msg.topic=\"2\"\nmsg.payload = \"to\"\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":80,"wires":[["f044da86.a607c8"]]},{"id":"6c84b3d9.4ee76c","type":"function","z":"fde1fdc8.696df","name":"Topic 3","func":"msg.topic=\"3\"\nmsg.payload = \"tre\"\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":200,"wires":[["f044da86.a607c8"]]},{"id":"fc97af08.a91658","type":"function","z":"fde1fdc8.696df","name":"Topic 4","func":"msg.topic=\"4\"\nmsg.payload = \"fire\"\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":40,"wires":[["f044da86.a607c8"]]},{"id":"f044da86.a607c8","type":"join","z":"fde1fdc8.696df","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":460,"y":180,"wires":[["6d23e5fe.225b14"]]},{"id":"bd5419ab.980818","type":"debug","z":"fde1fdc8.696df","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":320,"wires":[]},{"id":"6d23e5fe.225b14","type":"change","z":"fde1fdc8.696df","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":240,"wires":[["bd5419ab.980818"]]}]

Yeah, that won't work. Try this instead...

return [msg1, msg2, msg3, msg4];

This assumes msg1 ~ msg4 are all objects (i.e. {payload: "some value you wanna send"})

And just in case I missed something, you would need to set the function to have 4 outputs and msg1 would travel out of pin 1, msg2 would travel out of pin 2... Etc.

And just incase I missed something else, you can send msg1~4 out the same pin (serially) using either return [[msg1, msg2, msg3, msg4]] or node.send([msg1, msg2, msg3, msg4]);.

I highly recommend reading the Excellent documentation about
Working with messages. So many golden nuggets there to simplify your life and experience with node-red.

Disclaimer....
The code snippets above are off the top of my head. RTFM :wink: