Find value in array similar to SQL?

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:

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

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

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

Wow ! That reminds me of Mike Cowlishaws original Rexx manual

1 Like

I loved REXX and used it for a number of projects

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

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

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

image

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

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