Switch or function (or something else)?

New to NR, so this is probably easy...:slight_smile:

I've got a payload that includes the field "device_id" which is an integer. I need to check if this device_id is included in a list of device_id's (an array perhaps), about 15 total. If so the flow should stop, else it should continue. I've been stuck trying out different options using switch and function, but I've not been able to succeed.

A bit of help would be much appreciated!

use a function node:

const myIds = [1,2,3,4]

if (myIds.find(myId => myId == msg.payload.device_id)) {

See, I said it was easy :slight_smile: Thanks, now off to check if this will work for me!

Just to note that the code has a syntax error after .device_id, missing )

@mk1blacklimited you could also use includes().

const myIds = [1,2,3,4]
if (myIds.includes(msg.payload.device_id)) {
 return msg;
return null;

Thanks a lot @garrett and @E1cid, worked like a charm!

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