Function for sorting output by input

**Good day
We are starting with node red and I would like to ask if anyone could advise me.
The point is that I would need a function that would sort my input.
Now it does to me that when I send any input 1-4, the output is always sent to all 4 outputs.

I would need that when I send input 2, the output will only be on output 2 (Output 1,3,4, they don't get any signal).

I will be happy for any advice.
Thank you**

  return [
     msg.payload == 1 ? msg : null,
     msg.payload == 2 ? msg : null,
     msg.payload == 3 ? msg : null,
     msg.payload == 4 ? msg : null

NOTE: as you send in 1 or 2 or 3 or 4, there is no real need to create a new msg { payload:"1" } - just send the original msg.

NOTE: 2 why not just use a switch node? (is this an academic test?)

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