# Send different values from an array to different nodes?

**URL:** <https://discourse.nodered.org/t/send-different-values-from-an-array-to-different-nodes/78062>\
**Category:** General\
**Created:** [1 May 2023 10:28 UTC](https://discourse.nodered.org/t/send-different-values-from-an-array-to-different-nodes/78062 "2023-05-01T10:28:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [1 May 2023 10:28 UTC](https://discourse.nodered.org/t/send-different-values-from-an-array-to-different-nodes/78062/1 "2023-05-01T10:28:14Z")

</div>

Been searching and trying for a while but I still do something wrong. I have different values coming from the car once in a while (bluelinky). I need some of the values put to different output nodes. I have made a function node to get the values I want.

var newMsg = { payload: [msg.payload.evStatus.batteryStatus, msg.payload.battery.batSoc, msg.payload.evStatus.drvDistance[0].rangeByFuel.evModeRange.value, msg.payload.evStatus.batteryCharge, msg.payload.doorLock] };  
return newMsg;

Then I have used a split node with the settings split using payload and fixed lenght of 1. Then I get separated messages from the split node. But I struggle to use the Switch node to route the messages to the correct debug node. Is it possible to set this up in the switch node as it is? Or do I have to add topic in the function node first?

I will greatly appreciate any suggestions who can help me on the way fixing this.

Best regards  
Freddy

---

<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:** [1 May 2023 10:46 UTC](https://discourse.nodered.org/t/send-different-values-from-an-array-to-different-nodes/78062/2 "2023-05-01T10:46:59Z")

</div>

Instead of an array, make newmsg.payload a javascript object:

```auto
newMsg.payload = {
"status": msg.payload.evStatus.batteryStatus, 
"soc": msg.payload.battery.batSoc, 
"range": msg.payload.evStatus.drvDistance[0].rangeByFuel.evModeRange.value, 
"battery": msg.payload.evStatus.batteryCharge, 
"doorlock":msg.payload.doorLock
}

```

Then your downstream processing can operate on msg.payload.status or msg.payload.doorlock etc.

---

<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:** [1 May 2023 11:10 UTC](https://discourse.nodered.org/t/send-different-values-from-an-array-to-different-nodes/78062/3 "2023-05-01T11:10:25Z")

</div>

Yes, if you set the switch node property to msg.parts.index  
and the rules to equals number 0 or 1 or 2 or 3 etc.  
Have a look at the output of the split node, using a debug set to complete message object.

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [1 May 2023 11:21 UTC](https://discourse.nodered.org/t/send-different-values-from-an-array-to-different-nodes/78062/4 "2023-05-01T11:21:47Z")

</div>

Thank you E1cid, this did the trick. I do not know enough code to see the simple solutions yet, so I am very grateful when I get good help as this.

---

<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:** [15 May 2023 11:22 UTC](https://discourse.nodered.org/t/send-different-values-from-an-array-to-different-nodes/78062/5 "2023-05-15T11:22:34Z")

</div>

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