# Output non correct

**URL:** <https://discourse.nodered.org/t/output-non-correct/81276>\
**Category:** General\
**Created:** [13 September 2023 13:24 UTC](https://discourse.nodered.org/t/output-non-correct/81276 "2023-09-13T13:24:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [13 September 2023 13:24 UTC](https://discourse.nodered.org/t/output-non-correct/81276/1 "2023-09-13T13:24:19Z")

</div>

Hi, I try to explain .....  
this is the code:

![img1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f850651a94523a11f473c3cd9e2a94ff08c8ddf7.png)

```auto
const output = [null, null];

const x = msg.payload

if (x == 1)
{
    output[0] = { payload: "uno" }
    output[1] = { payload: "due" }
    setTimeout(() => { node.send(output[0]) }, 6000)
    setTimeout(() => { node.send(output[1]) }, 0)
}

```

I have the correct delay but for the same node (0) instead of "uno" for output [0]  
and "due" for output [1]

![img2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/7938b4df6c92813353a4193a6306a3addda614ab.png)

Where am I wrong?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 September 2023 13:32 UTC](https://discourse.nodered.org/t/output-non-correct/81276/2 "2023-09-13T13:32:19Z")

</div>

That output looks correct to me. You are sending `output[1]` after a zero ms timeout so it appears first and `output[0]` after a 6s delay. What did you expect?

Of course, a timeout with a zero delay is a bit pointless I think.

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [13 September 2023 13:38 UTC](https://discourse.nodered.org/t/output-non-correct/81276/3 "2023-09-13T13:38:49Z")

</div>

The second image ....  
both node: 0  
Instead

```auto
output[1] = { payload: "due" }

```

should be node: 1

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 September 2023 13:42 UTC](https://discourse.nodered.org/t/output-non-correct/81276/4 "2023-09-13T13:42:34Z")

</div>

> [@Giamma](#):
>
> should be node: 1

Urm, afraid not. Because you've only passed 1 element of `output` to each node.send. So both messages will appear from the top port of the function node and go to the debug marked `0` on your flow.

I think what you meant to do was something like this:

```auto
const output = [null, null];

const x = msg.payload

if (x == 1)
{
    output[0] = { payload: "uno" }
    output[1] = { payload: "due" }
    setTimeout(() => { node.send( [output[0], null] ) }, 6000)
    setTimeout(() => { node.send( [null, output[1]] ) }, 0)
}

```

If, instead, you did

```auto
const output = [null, null];

const x = msg.payload

if (x == 1)
{
    output[0] = { payload: "uno" }
    output[1] = { payload: "due" }
    setTimeout(() => { node.send(output) }, 6000)
    setTimeout(() => { node.send(output) }, 0)
}

```

You would get 4 outputs.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 September 2023 13:47 UTC](https://discourse.nodered.org/t/output-non-correct/81276/5 "2023-09-13T13:47:34Z")

</div>

Try

```auto
const output = [[null,null], [null,null]];

const x = msg.payload

if (x == 1)
{
    output[0][0] = { payload: "uno" }
    output[1][1] = { payload: "due" }
    setTimeout(() => { node.send(output[0]) }, 6000)
    setTimeout(() => { node.send(output[1]) }, 0)
}

```

OR

```auto
const output = [[null],[null]]
const x = msg.payload

if (x == 1)
{
    output[0].unshift({ payload: "uno" })
    output[1].push({ payload: "due" })
    setTimeout(() => { node.send(output[0]) }, 6000)
    setTimeout(() => { node.send(output[1]) }, 0)
}

```

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [13 September 2023 13:48 UTC](https://discourse.nodered.org/t/output-non-correct/81276/6 "2023-09-13T13:48:08Z")

</div>

Yes .....

```auto
const output = [null, null];

const x = msg.payload

if (x == 1)
{
    output[0] = { payload: "uno" }
    output[1] = { payload: "due" }
    setTimeout(() => { node.send( [output[0], null] ) }, 6000)
    setTimeout(() => { node.send( [null, output[1]] ) }, 0)
}

```

This is correct for me.  
Thank you very 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:** [27 September 2023 13:48 UTC](https://discourse.nodered.org/t/output-non-correct/81276/7 "2023-09-27T13:48:29Z")

</div>

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