hello,
I
want to extract from MQTT IN only one value, it returns me 14 values in the debug of which 13 are undefined, my code does not work.
Function code
var B1 = msg.payload.z.B1;
msg.payload = B1;
return msg;
hello,
I
Function code
var B1 = msg.payload.z.B1;
msg.payload = B1;
return msg;
Use a switch node instead:
It will pass the message if B1 exists in payload.z
Ofcourse it is also possible in a function node.
if("B1" in msg.payload?.z){
return msg
}
As @bakman2 says, you need to test that msg.payload.z contains the key B1.
Rather than using a function node you can easily achieve the same thing with core Node-red switch and change nodes:
Thanks for your help, it works.