# RED.utils.getObjectProperty expected output

**URL:** <https://discourse.nodered.org/t/red-utils-getobjectproperty-expected-output/30634>\
**Category:** Core Development\
**Created:** [23 July 2020 20:33 UTC](https://discourse.nodered.org/t/red-utils-getobjectproperty-expected-output/30634 "2020-07-23T20:33:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [23 July 2020 20:33 UTC](https://discourse.nodered.org/t/red-utils-getobjectproperty-expected-output/30634/1 "2020-07-23T20:33:02Z")

</div>

Would there be any reason why this function shouldn't always return _undefined_ if any one of the properties in the chain is _undefined_?

Example:

```javascript
var msg = {payload: {bar: 'last call'}};
RED.util.getObjectProperty(msg, 'payload.bar');
//returns 'last call'

RED.util.getObjectProperty(msg, 'payload.foo');
//returns undefined

RED.util.getObjectProperty(msg, 'payload.foo.bar');
//results in Uncaught TypeError: Cannot read property 'bar' of undefined

```

I would think it would be better that it simply returns _undefined_ if you mess up at any point in the chain.

I'm getting ready to send a PR, but wanted to check here first.

---

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [23 July 2020 20:41 UTC](https://discourse.nodered.org/t/red-utils-getobjectproperty-expected-output/30634/2 "2020-07-23T20:41:49Z")

</div>

Sorry! disregard. I just found the PR already asking about this.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [23 July 2020 20:43 UTC](https://discourse.nodered.org/t/red-utils-getobjectproperty-expected-output/30634/3 "2020-07-23T20:43:00Z")

</div>

Link ? ( to cross ref)

---

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [23 July 2020 20:58 UTC](https://discourse.nodered.org/t/red-utils-getobjectproperty-expected-output/30634/4 "2020-07-23T20:58:10Z")

</div>

> <https://github.com/node-red/node-red/pull/2398>

At first I was not seeing why this shouldn't be fixed, but now I'm thinking that it's nice to be able to differentiate between the child property not existing and one of the parent properties not existing. Maybe returning something other than _undefined_ but maybe the best solution is just to catch the error and work it case by case.

Thanks for listening...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 September 2020 20:58 UTC](https://discourse.nodered.org/t/red-utils-getobjectproperty-expected-output/30634/5 "2020-09-21T20:58:13Z")

</div>

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