# Find value in array similar to SQL?

**URL:** <https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684>\
**Category:** General\
**Created:** [28 December 2019 16:52 UTC](https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684 "2019-12-28T16:52:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gombol](https://avatars.discourse-cdn.com/v4/letter/g/58f4c7/32.png) [@Gombol](https://discourse.nodered.org/u/Gombol)\
**Post date:** [28 December 2019 16:52 UTC](https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684/1 "2019-12-28T16:52:39Z")

</div>

Hi,

in T-SQL it is possible to query the occurance of a specific value in an array of values like this:

`case when 27 in (12,13,16,17,18) then ....`

Is there something similar in Node-Red ?  
I know there are arrays but it seems to be too complicated for my request.

All I need is something like:

```auto
if incomingvalue.msg in (1,2,3,4,5) then do X
if incomingvalue.msg in (6,7,8,9,0) then do Y

```

BR  
Gombol

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 17:58 UTC](https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684/2 "2019-12-28T17:58:20Z")

</div>

```auto
haystack = [1,2,3,4,5]
needle = msg.payload

if(haystack.includes(needle)){
    return {payload:"found value"}
};

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [28 December 2019 18:01 UTC](https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684/3 "2019-12-28T18:01:53Z")

</div>

Wow ! That reminds me of Mike Cowlishaws original Rexx manual

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 December 2019 20:41 UTC](https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684/4 "2019-12-28T20:41:05Z")

</div>

I loved REXX and used it for a number of projects

---

<div class="post-metadata">

**Author:** ![Golonder](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@Golonder](https://discourse.nodered.org/u/Golonder)\
**Post date:** [30 December 2019 19:16 UTC](https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684/5 "2019-12-30T19:16:52Z")

</div>

Thanks in the name of Gombol - works fine and perfectly does what it should do 😄

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [3 January 2020 16:42 UTC](https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684/6 "2020-01-03T16:42:38Z")

</div>

> [@Gombol](#):
>
> case when 27 in (12,13,16,17,18)

Ooh, you were SO CLOSE to the answer!

You could try a `change` node with the JSONata expression:  
`payload in [12,13,16,17,18]`

The output `msg.payload` will be either a boolean `true` or `false`, which you can use in a `switch` node downstream to direct the flow... or better yet, just make that expression part of your switch!

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6713522e605317e8a93c142269f77ac69b24411d.png)

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [3 January 2020 16:49 UTC](https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684/7 "2020-01-03T16:49:27Z")

</div>

> [@Gombol](#):
>
> All I need is something like:
> 
> ```auto
> if incomingvalue.msg in (1,2,3,4,5) then do X
> if incomingvalue.msg in (6,7,8,9,0) then do Y
> 
> ```

Re-reading your original post, here is how you can implement your "case" statement in a `switch` node:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/77445d9a75e947457c9b09ad3813259c0a6a0f24.png)

---

<div class="post-metadata">

**Author:** ![Golonder](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@Golonder](https://discourse.nodered.org/u/Golonder)\
**Post date:** [3 January 2020 23:12 UTC](https://discourse.nodered.org/t/find-value-in-array-similar-to-sql/19684/8 "2020-01-03T23:12:18Z")

</div>

as I prefer writing code to configuring nodes i did it like that:

```auto
haystack = [1,3,5,7,9]
needle = parseInt(flow.get('ext_value')) || 0;
   
if(haystack.includes(needle))
{ do stuff }
else
{ do other stuff }

```
