# Send payload inside a loop (for)

**URL:** <https://discourse.nodered.org/t/send-payload-inside-a-loop-for/58426>\
**Category:** General\
**Created:** [16 February 2022 00:04 UTC](https://discourse.nodered.org/t/send-payload-inside-a-loop-for/58426 "2022-02-16T00:04:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lafayette](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@Lafayette](https://discourse.nodered.org/u/Lafayette)\
**Post date:** [16 February 2022 00:04 UTC](https://discourse.nodered.org/t/send-payload-inside-a-loop-for/58426/1 "2022-02-16T00:04:46Z")

</div>

Hi,

I have this function (node function / Tab On Message) :

```auto
const val = msg.payload;
let file_out = {};
for (var i = 0; i < val.length/4; i++){
    file_out = {
                'name' : val[i + val.length/2]._value,
                'lat' : val[i]._value, 
                'lon' : val[i + val.length/4]._value, 
                'Date' : val[i + val.length/2 + val.length/4]._value
                }; 
msg.payload = file_out;
return msg;
}

```

The input is an array with four columns. My problem is that the function send just once the result while the return msg is inside the loop, so i don't understand. Maybe because i'm new...

Thank you.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [16 February 2022 00:09 UTC](https://discourse.nodered.org/t/send-payload-inside-a-loop-for/58426/2 "2022-02-16T00:09:24Z")

</div>

Have a read of the documentation [Writing Functions : Node-RED](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)  
The asynchronous section

---

<div class="post-metadata">

**Author:** ![Lafayette](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@Lafayette](https://discourse.nodered.org/u/Lafayette)\
**Post date:** [16 February 2022 01:57 UTC](https://discourse.nodered.org/t/send-payload-inside-a-loop-for/58426/3 "2022-02-16T01:57:20Z")

</div>

Thx so much !

---

<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:** [2 March 2022 01:57 UTC](https://discourse.nodered.org/t/send-payload-inside-a-loop-for/58426/4 "2022-03-02T01:57:48Z")

</div>

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