# Using a Node that returns 2 msg.payload

**URL:** <https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713>\
**Category:** General\
**Created:** [15 June 2024 10:51 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713 "2024-06-15T10:51:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![damica51](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@damica51](https://discourse.nodered.org/u/damica51)\
**Post date:** [15 June 2024 10:51 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/1 "2024-06-15T10:51:57Z")

</div>

I'm using a node that returns (2) msg.payload see image, how do I address each msg.payload within a "Function" node?

 ![Example](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c992be3a521dd0b50e4bab7992b686f49cd9cb6.jpeg)

---

<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:** [15 June 2024 11:02 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/2 "2024-06-15T11:02:06Z")

</div>

How are you making the PING?

There seems a lot you aren't showing, so the question is not really answerable as given.

---

<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:** [15 June 2024 11:05 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/3 "2024-06-15T11:05:50Z")

</div>

The usual way to distinguish them would be by msg.topic, which in your case seems to be "1.1.1.1" or "8.8.8.8"

So in your function node you can have

```auto
if (msg.topic === "1.1.1.1") {
   blah
}
else if (msg.topic === "8.8.8.8") {
   blah
}
else {
   blah
}

```

You can also pass the messages through a join node in "Manual" mode (since they have different topics) which would result in a single message with properties msg.payload["1.1.1.1"] and msg.payload["8.8.8.8"]  
If you do this and have control of the topic, it would be better to use a string which does not begin with a digit - "cloudflare" and "google" spring to mind 😁  
That allows simpler notation msg.payload.cloudflare etc.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 June 2024 11:32 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/5 "2024-06-15T11:32:50Z")

</div>

This might be a better bet: [Ping Network Devices From a List - #12 by Steve-Mcl](https://discourse.nodered.org/t/ping-network-devices-from-a-list/43563/12)

---

<div class="post-metadata">

**Author:** ![damica51](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@damica51](https://discourse.nodered.org/u/damica51)\
**Post date:** [15 June 2024 14:00 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/6 "2024-06-15T14:00:38Z")

</div>

I have an array of 3 [0,1,2) and my msg.payload is showing the objects correctly msg.payload[0], msg.payload[1], msg.payload[2].

So here is my problem I can't figure out.  
I'm checking to see if all three are TRUE (Boolean) if they are how to I make (add) another array? msg.payload[3].

Example ; `If (msg.payload[0] != false && msg.payload[1] != false && msg.payload[2] != false) {msg.payload[3] === true} **This would be the array I need added** `

---

<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:** [15 June 2024 14:20 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/7 "2024-06-15T14:20:56Z")

</div>

> [@damica51](#):
>
> {msg.payload[3] === true}

This is a comparison not an assignment.

But the right way to add an element to an array is array.push()

```auto
if (msg.payload[0] != false && msg.payload[1] != false && msg.payload[2] != false) {
msg.payload.push (true)
}

```

---

<div class="post-metadata">

**Author:** ![damica51](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@damica51](https://discourse.nodered.org/u/damica51)\
**Post date:** [15 June 2024 14:23 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/8 "2024-06-15T14:23:28Z")

</div>

Thanks for catching my error! I will try the array.push()

---

<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:** [15 June 2024 14:26 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/9 "2024-06-15T14:26:10Z")

</div>

You can also use

```auto
if (! msg.payload.includes (false)) {
   msg.payload.push(true)
}

```

---

<div class="post-metadata">

**Author:** ![damica51](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@damica51](https://discourse.nodered.org/u/damica51)\
**Post date:** [15 June 2024 14:32 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/10 "2024-06-15T14:32:28Z")

</div>

Thank you so much, it is working as I hoped. And thanks for the tips.

---

<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:** [29 June 2024 14:33 UTC](https://discourse.nodered.org/t/using-a-node-that-returns-2-msg-payload/88713/11 "2024-06-29T14:33:07Z")

</div>

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