# How check undefined msg in a function node?

**URL:** https://discourse.nodered.org/t/how-check-undefined-msg-in-a-function-node/51263
**Category:** General
**Created:** [20 September 2021 03:02 UTC](https://discourse.nodered.org/t/how-check-undefined-msg-in-a-function-node/51263 "2021-09-20T03:02:25Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![essereumano](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/essereumano/32/48262_2.png) [@essereumano](https://discourse.nodered.org/u/essereumano)
#### Post date: [20 September 2021 06:59 UTC](https://discourse.nodered.org/t/how-check-undefined-msg-in-a-function-node/51263/6 "2021-09-20T06:59:58Z")

</div>

@zenofmud yes, i tried but the error is coming when msg.payload[0] is undefined and not when have a value. I don't find an all in one solution.

To be clearer I enter the full code:

```auto
if (msg.payload[0] != "undefined"){

   if (msg.payload[0].r_id > 0 && msg.payload[0].r_id != "undefined"){

        let formatobject = [{ "Nessuno": 0 }];

        for (let i = 0; i < msg.payload.length; i++) {

            let tempnome = msg.payload[i].r_nome;

            let tempid = msg.payload[i].r_id;

            let tempobject = {};

            tempobject[tempnome] = tempid;

            formatobject.push(tempobject);

        }

        msg1.options = formatobject;

        node.send([msg1, null, null, null, null, null, null]);

   }

}

```

---

_[View the full topic](https://discourse.nodered.org/t/how-check-undefined-msg-in-a-function-node/51263)._
