# How to send payload for each iteration (function node) a payload to MQTT node?

**URL:** <https://discourse.nodered.org/t/how-to-send-payload-for-each-iteration-function-node-a-payload-to-mqtt-node/15715>\
**Category:** General\
**Created:** [20 September 2019 10:55 UTC](https://discourse.nodered.org/t/how-to-send-payload-for-each-iteration-function-node-a-payload-to-mqtt-node/15715 "2019-09-20T10:55:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)\
**Post date:** [20 September 2019 10:55 UTC](https://discourse.nodered.org/t/how-to-send-payload-for-each-iteration-function-node-a-payload-to-mqtt-node/15715/1 "2019-09-20T10:55:10Z")

</div>

hello firends,  
this is my function:

```auto
var LastCommands = msg.payload.split('\n')
global.set("LastCommands", LastCommands);
LastCommands.forEach(function(command) {
   // send each "command" with 250ms delay to MQTT node
});

```

How can I send a msg.payload for each iteration in the loop to an other node (MQTT) ?  
Thx !

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [20 September 2019 11:02 UTC](https://discourse.nodered.org/t/how-to-send-payload-for-each-iteration-function-node-a-payload-to-mqtt-node/15715/2 "2019-09-20T11:02:16Z")

</div>

See the docs

[https://nodered.org/docs/user-guide/writing-functions#multiple-messages](https://nodered.org/docs/user-guide/writing-functions#multiple-messages)  
[https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 September 2019 11:25 UTC](https://discourse.nodered.org/t/how-to-send-payload-for-each-iteration-function-node-a-payload-to-mqtt-node/15715/3 "2019-09-20T11:25:12Z")

</div>

or instead - use a split node (that will emit one msg per line (\n) - then a delay node in rate limit mode set to 250mS

---

<div class="post-metadata">

**Author:** ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)\
**Post date:** [20 September 2019 11:28 UTC](https://discourse.nodered.org/t/how-to-send-payload-for-each-iteration-function-node-a-payload-to-mqtt-node/15715/4 "2019-09-20T11:28:41Z")

</div>

thx!  
I made it like this:

```auto
var LastCommands = msg.payload.split('\n')
global.set("LastCommands", LastCommands);
LastCommands.forEach(function(command) {
   node.send({payload:command});
});

```

...plus random delay node
