# How to check if a value is in array using the switch node

**URL:** https://discourse.nodered.org/t/how-to-check-if-a-value-is-in-array-using-the-switch-node/76262
**Category:** General
**Created:** [7 March 2023 20:02 UTC](https://discourse.nodered.org/t/how-to-check-if-a-value-is-in-array-using-the-switch-node/76262 "2023-03-07T20:02:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dcaccount](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@dcaccount](https://discourse.nodered.org/u/dcaccount)
#### Post date: [7 March 2023 20:02 UTC](https://discourse.nodered.org/t/how-to-check-if-a-value-is-in-array-using-the-switch-node/76262/1 "2023-03-07T20:02:49Z")

</div>

Hello,  
I am quite new to Node Red and I need to ask for your help as I cannot solve a simple problem.

I have a flow where the mgs.payload is an array like

["Intrusion","Alarm","Input"]

I would like to introduce a switch depending on the value of the second field of msg.payload.  
I have tried to introduce the switch node with property msg.payload[1] and then == string "Alarm" but it won't work.

Can you please help?  
Thanks in advance,  
Daniele

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [7 March 2023 20:12 UTC](https://discourse.nodered.org/t/how-to-check-if-a-value-is-in-array-using-the-switch-node/76262/2 "2023-03-07T20:12:17Z")

</div>

Its working for me

Example Flow

```auto
[{"id":"d61f4d428d068cd7","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"Intrusion\",\"Alarm\",\"Input\"]","payloadType":"json","x":260,"y":1800,"wires":[["3f22d122d79c0faf"]]},{"id":"3f22d122d79c0faf","type":"switch","z":"54efb553244c241f","name":"Alarm","property":"payload[1]","propertyType":"msg","rules":[{"t":"eq","v":"Alarm","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":1800,"wires":[["fdf8a1d049967a2d"]]},{"id":"fdf8a1d049967a2d","type":"debug","z":"54efb553244c241f","name":"debug 29","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":1800,"wires":[]},{"id":"82d1b19984d0c573","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"Intrusion\",\"Alarm\",\"Input\"]","payloadType":"json","x":270,"y":1900,"wires":[["782adf6649f8460d"]]},{"id":"782adf6649f8460d","type":"switch","z":"54efb553244c241f","name":"Alarmmmm","property":"payload[1]","propertyType":"msg","rules":[{"t":"eq","v":"Alarmmmm","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":430,"y":1900,"wires":[["a73f5ba2dee9358c"]]},{"id":"a73f5ba2dee9358c","type":"debug","z":"54efb553244c241f","name":"debug 30","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":1900,"wires":[]}]

```

maybe your array is not an array but a string ?

---

<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: [7 March 2023 20:12 UTC](https://discourse.nodered.org/t/how-to-check-if-a-value-is-in-array-using-the-switch-node/76262/3 "2023-03-07T20:12:29Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/df4d08276c8a139115206f1dd8c4e891f8fba780.png)

---

<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: [7 March 2023 20:12 UTC](https://discourse.nodered.org/t/how-to-check-if-a-value-is-in-array-using-the-switch-node/76262/4 "2023-03-07T20:12:37Z")

</div>

Are you sure the input is an arrray, not a string?

When I inject that as an array, the switch node recognises msg.payload[1] == "Alarm"

Edit: SNAP!

---

<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: [21 March 2023 20:13 UTC](https://discourse.nodered.org/t/how-to-check-if-a-value-is-in-array-using-the-switch-node/76262/5 "2023-03-21T20:13:12Z")

</div>

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