# Sending multiple msg from function node

**URL:** <https://discourse.nodered.org/t/sending-multiple-msg-from-function-node/87399>\
**Category:** General\
**Created:** [21 April 2024 22:43 UTC](https://discourse.nodered.org/t/sending-multiple-msg-from-function-node/87399 "2024-04-21T22:43:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RedRobin132](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@RedRobin132](https://discourse.nodered.org/u/RedRobin132)\
**Post date:** [21 April 2024 22:43 UTC](https://discourse.nodered.org/t/sending-multiple-msg-from-function-node/87399/1 "2024-04-21T22:43:54Z")

</div>

Hello!  
In a function node, i get (as input) an array of multiple objects. Now i want to extract one string from each object (all objects are built the same) and send each string separately over one node-output.  
Is that possible?

Thanks in advance  
Robin

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 April 2024 23:49 UTC](https://discourse.nodered.org/t/sending-multiple-msg-from-function-node/87399/2 "2024-04-21T23:49:22Z")

</div>

Are you wanting to send all the messages out the same output?

If yes:

You do a `node.send()` command, rather than the `return msg` command.

So...

You would get the incoming message, split it up into the required bits and then `node.send()` for each part.

That is a real basic overview but I hope it helps.

Dunno how good this example is, but.....

```auto
[{"id":"7ff1fa4571033fb7","type":"function","z":"7e987ddf260bdf0d","name":"function 44","func":"let x = msg.payload;\nlet vA = msg.payload[1];\nlet vB = msg.payload[2];\nlet vC = msg.payload[3];\n\nlet msg1 = {\"payload\":vA};\nlet msg2 = {\"payload\":vB};\nlet msg3 = {\"payload\":vC};\n\nnode.send(msg1);\nnode.send(msg2);\nnode.send(msg3);","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2890,"y":4650,"wires":[["b832f9bd4fd872a8"]]},{"id":"41e8f1532772ef96","type":"inject","z":"7e987ddf260bdf0d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"1\":\"a\",\"2\":\"b\",\"3\":\"c\"}","payloadType":"json","x":2680,"y":4650,"wires":[["7ff1fa4571033fb7","a7d27cc3363f8782"]]},{"id":"b832f9bd4fd872a8","type":"debug","z":"7e987ddf260bdf0d","name":"Split","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":3160,"y":4650,"wires":[]},{"id":"a7d27cc3363f8782","type":"debug","z":"7e987ddf260bdf0d","name":"Going in","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2880,"y":4600,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 April 2024 00:52 UTC](https://discourse.nodered.org/t/sending-multiple-msg-from-function-node/87399/3 "2024-04-22T00:52:28Z")

</div>

A low-code approach without using a function node:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/cad3315fc4112b40374fd513ed29f6a146c265c2.png)

```auto
[{"id":"1c22da8356c1b02b","type":"inject","z":"5c74cb9708ad35f2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":220,"wires":[["cb5500dc47be6855"]]},{"id":"cb5500dc47be6855","type":"change","z":"5c74cb9708ad35f2","name":"Input data","rules":[{"t":"set","p":"payload","pt":"msg","to":"[{\"artist\":\"Poussin\",\"work\":\"Et in Arcadia Ego\"},{\"artist\":\"Van Eyck\",\"work\":\"St Barbara\"},{\"artist\":\"Rembrandt\",\"work\":\"An Elephant\"}]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":220,"wires":[["605df9858753148e","bc24dc603eef50db"]]},{"id":"605df9858753148e","type":"change","z":"5c74cb9708ad35f2","name":"\"work\" property of each array element","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.work","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":280,"wires":[["b9fe67ee07bd5811"]]},{"id":"e96ea5c80297c7da","type":"debug","z":"5c74cb9708ad35f2","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":280,"wires":[]},{"id":"b9fe67ee07bd5811","type":"split","z":"5c74cb9708ad35f2","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":650,"y":280,"wires":[["e96ea5c80297c7da"]]},{"id":"bc24dc603eef50db","type":"debug","z":"5c74cb9708ad35f2","name":"Input data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":220,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![RedRobin132](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@RedRobin132](https://discourse.nodered.org/u/RedRobin132)\
**Post date:** [22 April 2024 10:58 UTC](https://discourse.nodered.org/t/sending-multiple-msg-from-function-node/87399/4 "2024-04-22T10:58:41Z")

</div>

Thanks, that is exactly, what i was searching for!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 July 2024 10:59 UTC](https://discourse.nodered.org/t/sending-multiple-msg-from-function-node/87399/5 "2024-07-21T10:59:11Z")

</div>

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