Or as @gerry said, why not re-write the construct with 'if' and 'else if'
The 'if' 'else' ladder will exit as soon as the first match is found.
var A = "";
var B = "";
var C = "";
if (msg.payload == 0) {
A = msg.payload;
}
else if (msg.payload == 1) {
B = msg.payload;
}
else {
C = msg.payload;
}
msg.payload = {}; // Clear original payload so a payload object can be used
msg.payload.red = A;
msg.payload.yellow = B;
msg.payload.green = C;
return msg;
Here's a simple test flow.
[{"id":"9faa33101efec6d3","type":"function","z":"b7043698e086d930","name":"","func":"var A = \"\";\nvar B = \"\";\nvar C = \"\";\n\nif (msg.payload == 0) {\n A = msg.payload;\n}\nelse if (msg.payload == 1) {\n B = msg.payload;\n}\nelse {\n C = msg.payload;\n}\n\n// msg.payload = {}; // Clear msg.payload so a new entity can be added\n\nmsg.payload.red = A;\nmsg.payload.yellow = B;\nmsg.payload.green = C;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":260,"wires":[["1788c466b24cad9c"]]},{"id":"c753c50c29a45883","type":"inject","z":"b7043698e086d930","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":250,"y":220,"wires":[["9faa33101efec6d3"]]},{"id":"1788c466b24cad9c","type":"debug","z":"b7043698e086d930","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":260,"wires":[]},{"id":"65d770e43b7c31c1","type":"inject","z":"b7043698e086d930","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":250,"y":260,"wires":[["9faa33101efec6d3"]]},{"id":"f29a1a5330c3d4a1","type":"inject","z":"b7043698e086d930","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":250,"y":300,"wires":[["9faa33101efec6d3"]]},{"id":"ffd03712faf0a3d8","type":"inject","z":"b7043698e086d930","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":250,"y":340,"wires":[["9faa33101efec6d3"]]}]