How to test for undefined in function node

Hi @smcgann99

You can check if it exists using something like:

if (msg.payload.hasOwnProperty("S29cmnd_D15")) {
   msg.payload = msg.payload.S29cmnd_D15.STATE;
   return msg;
} else {
  // do something else because it does not exist
}

Note how this code updates and returns the existing msg object, rather than create a new message object - that's generally the best practise to follow.

3 Likes