# How to switch based on array value

**URL:** <https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543>\
**Category:** General\
**Created:** [12 March 2026 21:48 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543 "2026-03-12T21:48:58Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![omega\_elite](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@omega\_elite](https://discourse.nodered.org/u/omega_elite)\
**Post date:** [12 March 2026 21:48 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/1 "2026-03-12T21:48:58Z")

</div>

Hi

i am new to node red and would like to know how to do the following.

I have 8 digital input values( true or false ) that are coming in on msg.payload as an array [false,false,false,false,false,false,false,false] and i would like to trigger outputs based on the true or false value of each array index.

---

<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:** [12 March 2026 22:15 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/2 "2026-03-12T22:15:16Z")

</div>

You could do a few ways. Off the top of my head:

- via a function node set to have 8 output and the code set to `return msg.payload.map(e => {return {payload:e}})`
- wire the msg to 8 change nodes that SETs the value of `msg.payload` to `msg.payload[x]` (where x is 0~7)

> [@omega\_elite](#):
>
> i am new to node red

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [13 March 2026 07:09 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/3 "2026-03-13T07:09:41Z")

</div>

> [@Steve-Mcl](#):
>
> via a function node set to have 8 output and the code set to `return msg.payload.map(e => {return {payload:e}})`

Here's a quick demo using **Steve's Map Method**...

 ![Friday_map_method](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/5518712b0c7491811e0803d5d4f6bf24f0dde3b1.jpeg)

And here's the **Node-RED flow** , so you can **Import it and try it out**...

```auto
[{"id":"d0d670bd0a5b6772","type":"tab","label":"Map function demo","disabled":false,"info":"","env":[]},{"id":"8959eb7e7a67cc21","type":"function","z":"d0d670bd0a5b6772","name":"Array Mapping","func":"// return msg.payload.map(e => ({ payload: e }));\n\n// Return only if an input is true, null is false\n// Uncomment the next line and comment-out the first line\n \nreturn msg.payload.map(e => e ? { payload: e } : null);","outputs":8,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":280,"wires":[["e0b650c1687fc97f"],["2676a4a1c86798e0"],["7087deea270ed147"],["815e704f0cc8b762"],["d4e24d66b9a144bc"],["d335eb5abfe68df1"],["b89a22a259ce35ea"],["c70a2db23ac35081"]]},{"id":"2267674ab1c3bbd6","type":"inject","z":"d0d670bd0a5b6772","name":"Test","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":210,"y":280,"wires":[["de7de090fd54ad38"]]},{"id":"de7de090fd54ad38","type":"function","z":"d0d670bd0a5b6772","name":"Array pattern","func":"msg.payload = [true,false,false,false,false,false,false,false];\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":280,"wires":[["8959eb7e7a67cc21"]]},{"id":"e0b650c1687fc97f","type":"debug","z":"d0d670bd0a5b6772","name":"MSB","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":140,"wires":[]},{"id":"2676a4a1c86798e0","type":"debug","z":"d0d670bd0a5b6772","name":"debug 3575","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":180,"wires":[]},{"id":"7087deea270ed147","type":"debug","z":"d0d670bd0a5b6772","name":"debug 3576","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":220,"wires":[]},{"id":"815e704f0cc8b762","type":"debug","z":"d0d670bd0a5b6772","name":"debug 3577","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":260,"wires":[]},{"id":"d4e24d66b9a144bc","type":"debug","z":"d0d670bd0a5b6772","name":"debug 3578","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":300,"wires":[]},{"id":"d335eb5abfe68df1","type":"debug","z":"d0d670bd0a5b6772","name":"debug 3579","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":340,"wires":[]},{"id":"b89a22a259ce35ea","type":"debug","z":"d0d670bd0a5b6772","name":"debug 3580","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":380,"wires":[]},{"id":"c70a2db23ac35081","type":"debug","z":"d0d670bd0a5b6772","name":"LSB","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":420,"wires":[]},{"id":"25dfae1fd97e1bfd","type":"comment","z":"d0d670bd0a5b6772","name":"Using .map method","info":"","x":570,"y":200,"wires":[]}]

```

 ![Friday_map_method_debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/f/bfc864ac33d0a8919befe18e28cb83e8cfef012a.jpeg)  
The JavaScript in the function node can be adapted **so only inputs that are 'true' are shown** on the outport port(s) by using this...

```auto
return msg.payload.map(e => e ? { payload: e } : null);

```

 ![Friday_map_method_only_true](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/a/facc1ee8289faa67ccbe9f5db608ba41cd89d7b1.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 March 2026 09:06 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/4 "2026-03-13T09:06:41Z")

</div>

There may be a simpler way, exactly how do you trigger an output?

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [16 March 2026 13:05 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/5 "2026-03-16T13:05:40Z")

</div>

Just interested to hear if you have had time to try out the various suggestions?

---

<div class="post-metadata">

**Author:** ![omega\_elite](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@omega\_elite](https://discourse.nodered.org/u/omega_elite)\
**Post date:** [18 March 2026 11:56 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/6 "2026-03-18T11:56:34Z")

</div>

Hi

No this did not work.........I did have a solution that i found online that used a split node before the switch node that worked but i managed to delete it and now cant find the solution i found online

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 March 2026 12:13 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/7 "2026-03-18T12:13:04Z")

</div>

> [@omega\_elite](#):
>
> No this did not work..

Using a debug node show us what is going into the function (screenshot, expand any objects shown there first) and Export the function node and paste it here.

---

<div class="post-metadata">

**Author:** ![omega\_elite](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@omega\_elite](https://discourse.nodered.org/u/omega_elite)\
**Post date:** [18 March 2026 12:17 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/8 "2026-03-18T12:17:22Z")

</div>

```auto
[
    {
        "id": "7e8a445cd9f1f429",
        "type": "modbus-read",
        "z": "d0d670bd0a5b6772",
        "name": "",
        "topic": "",
        "showStatusActivities": false,
        "logIOActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "Input",
        "adr": "0",
        "quantity": "1",
        "rate": "2",
        "rateUnit": "s",
        "delayOnStart": false,
        "enableDeformedMessages": false,
        "startDelayTime": "",
        "server": "733fb84059b76a0f",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "x": 130,
        "y": 300,
        "wires": [
            [],
            [
                "637f6e872ed32b51"
            ]
        ]
    },
    {
        "id": "637f6e872ed32b51",
        "type": "split",
        "z": "d0d670bd0a5b6772",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "property": "payload",
        "x": 310,
        "y": 320,
        "wires": [
            [
                "328eea9b0acbf03e"
            ]
        ]
    },
    {
        "id": "328eea9b0acbf03e",
        "type": "switch",
        "z": "d0d670bd0a5b6772",
        "name": "",
        "property": "parts.index",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "parts[0]",
                "vt": "msg"
            },
            {
                "t": "eq",
                "v": "parts[1]",
                "vt": "msg"
            },
            {
                "t": "eq",
                "v": "parts[2]",
                "vt": "msg"
            },
            {
                "t": "eq",
                "v": "parts[3]",
                "vt": "msg"
            },
            {
                "t": "eq",
                "v": "parts[4]",
                "vt": "msg"
            },
            {
                "t": "eq",
                "v": "parts[5]",
                "vt": "msg"
            },
            {
                "t": "eq",
                "v": "parts[6]",
                "vt": "msg"
            },
            {
                "t": "eq",
                "v": "parts[7]",
                "vt": "msg"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 8,
        "x": 470,
        "y": 320,
        "wires": [
            [
                "30c4cb7230d3622f",
                "c9f1b293ac7d7bcf"
            ],
            [
                "ddedc2863e52e014",
                "2963765f6c05b830"
            ],
            [
                "e43deb24212749ad",
                "47a729a6de098d2c"
            ],
            [
                "c2e9b0405d4e31fd",
                "13f6efe2e10c5de9"
            ],
            [
                "945773ec01f32003",
                "aff3470865645d7b"
            ],
            [
                "822b7da1a72e5afc",
                "89b9bafba6b24bf3"
            ],
            [
                "98ec17257870c06f",
                "43dc7c3b02aed743"
            ],
            [
                "23f184ad51532e4b",
                "92c7c889b73b55d3"
            ]
        ]
    },
    {
        "id": "30c4cb7230d3622f",
        "type": "debug",
        "z": "d0d670bd0a5b6772",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 140,
        "wires": []
    },
    {
        "id": "ddedc2863e52e014",
        "type": "debug",
        "z": "d0d670bd0a5b6772",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 220,
        "wires": []
    },
    {
        "id": "e43deb24212749ad",
        "type": "debug",
        "z": "d0d670bd0a5b6772",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 300,
        "wires": []
    },
    {
        "id": "c2e9b0405d4e31fd",
        "type": "debug",
        "z": "d0d670bd0a5b6772",
        "name": "debug 4",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 380,
        "wires": []
    },
    {
        "id": "945773ec01f32003",
        "type": "debug",
        "z": "d0d670bd0a5b6772",
        "name": "debug 5",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 460,
        "wires": []
    },
    {
        "id": "822b7da1a72e5afc",
        "type": "debug",
        "z": "d0d670bd0a5b6772",
        "name": "debug 6",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 540,
        "wires": []
    },
    {
        "id": "98ec17257870c06f",
        "type": "debug",
        "z": "d0d670bd0a5b6772",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 620,
        "wires": []
    },
    {
        "id": "23f184ad51532e4b",
        "type": "debug",
        "z": "d0d670bd0a5b6772",
        "name": "debug 8",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 700,
        "wires": []
    },
    {
        "id": "c9f1b293ac7d7bcf",
        "type": "modbus-write",
        "z": "d0d670bd0a5b6772",
        "name": "Relay 1",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "Coil",
        "adr": "0",
        "quantity": "1",
        "server": "733fb84059b76a0f",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 680,
        "y": 180,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "2963765f6c05b830",
        "type": "modbus-write",
        "z": "d0d670bd0a5b6772",
        "name": "Relay 2",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "Coil",
        "adr": "1",
        "quantity": "1",
        "server": "733fb84059b76a0f",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 680,
        "y": 260,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "47a729a6de098d2c",
        "type": "modbus-write",
        "z": "d0d670bd0a5b6772",
        "name": "Relay 3",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "Coil",
        "adr": "2",
        "quantity": "1",
        "server": "733fb84059b76a0f",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 680,
        "y": 340,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "13f6efe2e10c5de9",
        "type": "modbus-write",
        "z": "d0d670bd0a5b6772",
        "name": "Relay 4",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "Coil",
        "adr": "3",
        "quantity": "1",
        "server": "733fb84059b76a0f",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 680,
        "y": 420,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "aff3470865645d7b",
        "type": "modbus-write",
        "z": "d0d670bd0a5b6772",
        "name": "Relay 5",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "Coil",
        "adr": "4",
        "quantity": "1",
        "server": "733fb84059b76a0f",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 680,
        "y": 500,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "89b9bafba6b24bf3",
        "type": "modbus-write",
        "z": "d0d670bd0a5b6772",
        "name": "Relay 6",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "Coil",
        "adr": "5",
        "quantity": "1",
        "server": "733fb84059b76a0f",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 680,
        "y": 580,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "43dc7c3b02aed743",
        "type": "modbus-write",
        "z": "d0d670bd0a5b6772",
        "name": "Relay 7",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "Coil",
        "adr": "6",
        "quantity": "1",
        "server": "733fb84059b76a0f",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 680,
        "y": 660,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "92c7c889b73b55d3",
        "type": "modbus-write",
        "z": "d0d670bd0a5b6772",
        "name": "Relay 8",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "Coil",
        "adr": "7",
        "quantity": "1",
        "server": "733fb84059b76a0f",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 680,
        "y": 740,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "733fb84059b76a0f",
        "type": "modbus-client",
        "name": "",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "192.168.1.101",
        "tcpPort": 502,
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": 9600,
        "serialDatabits": 8,
        "serialStopbits": 1,
        "serialParity": "none",
        "serialConnectionDelay": 100,
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": 1,
        "commandDelay": 1,
        "clientTimeout": 1000,
        "reconnectOnTimeout": true,
        "reconnectTimeout": 2000,
        "parallelUnitIdsAllowed": true,
        "showErrors": false,
        "showWarnings": true,
        "showLogs": true
    },
    {
        "id": "72033a3f75b427cc",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-contrib-modbus": "5.45.2"
        }
    }
]

```

---

<div class="post-metadata">

**Author:** ![omega\_elite](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@omega\_elite](https://discourse.nodered.org/u/omega_elite)\
**Post date:** [18 March 2026 12:18 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/9 "2026-03-18T12:18:52Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/240d307747e2390cecd4f17074e32bc14bcdbadb.png)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [18 March 2026 12:55 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/10 "2026-03-18T12:55:31Z")

</div>

> [@omega\_elite](#):
>
> coming in on msg.payload as an array [false,false,false,false,false,false,false,false

**Does your Modbus really output an array like you stated in your initial posting?**  
That is what I based my demo flow on.  
Did **you** try the Demo Flow as it worked on my Raspberry Pi?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 March 2026 13:31 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/11 "2026-03-18T13:31:01Z")

</div>

> [@Colin](#):
>
> Using a debug node show us what is going into the function (screenshot, expand any objects shown there first)

You have not done that. In fact also show us what is coming out of the modbus node.

---

<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:** [18 March 2026 14:07 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/12 "2026-03-18T14:07:50Z")

</div>

If you are splitting a array with the split node, you should be using msg.parts.index and == number 0,1,2,3, etc

e.g

 ![image32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/647397703abe2d73f73e689f1161e2d710439383.png)

---

<div class="post-metadata">

**Author:** ![omega\_elite](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@omega\_elite](https://discourse.nodered.org/u/omega_elite)\
**Post date:** [18 March 2026 14:35 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/13 "2026-03-18T14:35:27Z")

</div>

yes i tried that but did not work....no the output is looking for a boolean value.....in modbus input is [false,false,false,false,false,false,false,false] which is the current state of each input but goes to true when an input is closed

---

<div class="post-metadata">

**Author:** ![omega\_elite](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@omega\_elite](https://discourse.nodered.org/u/omega_elite)\
**Post date:** [18 March 2026 14:38 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/14 "2026-03-18T14:38:33Z")

</div>

this is what is coming in on the modbus input

18/03/2026, 14:36:35[node: debug 4](https://192.168.0.69:1881/#)polling : msg : Object

object

topic: "polling"

payload: object

data: array[8]

0: false

1: false

2: false

3: false

4: false

5: false

6: false

7: false

buffer: buffer[1]

0: 0x0

values: array[8]

0: false

1: false

2: false

3: false

4: false

5: false

6: false

7: false

input: object

topic: "polling"

from: ""

payload: object

queueLengthByUnitId: object

queueUnitId: 1

unitId: 1

sendingNodeId: "8f3dfaf360c57a2f"

\_msgid: "9d6fb8e854565892"

---

<div class="post-metadata">

**Author:** ![omega\_elite](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@omega\_elite](https://discourse.nodered.org/u/omega_elite)\
**Post date:** [18 March 2026 14:58 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/15 "2026-03-18T14:58:13Z")

</div>

Hi

Have done that but still no joy !!!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/02e49cdd7a4b88bd9f150f2d312e7a51bc258bef.png)

---

<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:** [18 March 2026 15:45 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/16 "2026-03-18T15:45:39Z")

</div>

Hi, when you copy data from the debug, please use the "Copy Value" button to get good valid JSON representation

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

> [@omega\_elite](#):
>
> payload: object
> 
> data: array[8]

Since the value appears to be in payload.data, you can simply do what I suggested in my first post

> [@Steve-Mcl](#):
>
> via a function node set to have 8 output and the code set to `return msg.payload.map(e => {return {payload:e}})`

but using `msg.payload.data` of course

### Demo

![chrome_CHNrnMYghl](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a57fcc9918cac4ee0f2a3da582b6a59562d9c31.gif)

```js
return msg.payload.data.map(e => { return { payload: e } })

```

demo flow (use `CTRL+I` to import)

```auto
[{"id":"fb165d75c3c39be2","type":"function","z":"7ecf422396bf31b4","name":"function 2","func":"return msg.payload.data.map(e => { return { payload: e } })\n","outputs":8,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":1140,"wires":[["0498ae635bb28812"],["69f92c42d33f1b17"],["4fa9344a11984b75"],["78e2347950aac4db"],[],[],[],[]]},{"id":"b358ec1e5705c108","type":"inject","z":"7ecf422396bf31b4","name":"fake modus array of coils","props":[{"p":"payload.data","v":"[true, false, true, false,true, false, true, false]","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":260,"y":1140,"wires":[["fb165d75c3c39be2"]]},{"id":"0498ae635bb28812","type":"debug","z":"7ecf422396bf31b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":1000,"wires":[]},{"id":"69f92c42d33f1b17","type":"debug","z":"7ecf422396bf31b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":1060,"wires":[]},{"id":"4fa9344a11984b75","type":"debug","z":"7ecf422396bf31b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":1120,"wires":[]},{"id":"78e2347950aac4db","type":"debug","z":"7ecf422396bf31b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":1180,"wires":[]}]

```

---

<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:** [18 March 2026 18:02 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/17 "2026-03-18T18:02:45Z")

</div>

What does a debug node after the split node reveal?

As Steve has pointed out, it looks like you should be in msg.payload.data.

Either,

move msg,payload.data to msg.payload, your individual items of data would be in msg.payload after the split.

or

split msg.payload.data, your individual values would then be in msg.payload.data after the split.

---

<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:** [16 June 2026 18:03 UTC](https://discourse.nodered.org/t/how-to-switch-based-on-array-value/100543/18 "2026-06-16T18:03:29Z")

</div>

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