# Problems accessing an object

**URL:** https://discourse.nodered.org/t/problems-accessing-an-object/85125
**Category:** General
**Created:** [1 February 2024 15:13 UTC](https://discourse.nodered.org/t/problems-accessing-an-object/85125 "2024-02-01T15:13:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)
#### Post date: [1 February 2024 15:13 UTC](https://discourse.nodered.org/t/problems-accessing-an-object/85125/1 "2024-02-01T15:13:57Z")

</div>

I am trying to get the data contained in the events in this object:

 ![Screenshot 2024-02-01 at 17.03.00](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/808cada46c094851ae664350b0525ac6ba79d3df.png)  
If I copy the path of the first object (0: object) it gives me: area.info.events[0]

But when I run the function:

```auto
msg.payload = msg.area.info.events.map(event => {
    return {
        start: event.start,
        end: event.end,
        note: event.note
    };
});

return msg;

```

I get "TypeError: Cannot read properties of undefined (reading 'info')"  
The path looks correct to me. What am I doing wrong?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [1 February 2024 15:28 UTC](https://discourse.nodered.org/t/problems-accessing-an-object/85125/2 "2024-02-01T15:28:51Z")

</div>

> [@FeliceM](#):
>
> The path looks correct to me

Use the "copy path" tools node-red provides to ensure correct path.

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

* * *

Additionally, use `node.warn` in your function e.g. `node.warn({"msg.area": msg.area})` just before you access it.

* * *

Lastly, this is easier with the split and join nodes 🙂

---

<div class="post-metadata">

### Author: ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)
#### Post date: [1 February 2024 16:21 UTC](https://discourse.nodered.org/t/problems-accessing-an-object/85125/3 "2024-02-01T16:21:33Z")

</div>

Thanks but I copied the path “ If I copy the path of the first object (0: object) it gives me: area.info.events[0]”

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [1 February 2024 16:37 UTC](https://discourse.nodered.org/t/problems-accessing-an-object/85125/4 "2024-02-01T16:37:18Z")

</div>

> [@FeliceM](#):
>
> gives me: area.info.events[0]

That confirms _that_ message contained `.area.info.events` and it was an array THIS TIME, but as you did see the below error at some point \_

> [@FeliceM](#):
>
> "TypeError: Cannot read properties of undefined (reading 'info')"

\_ it suggests a previous `msg` came through WITHOUT `.area` resulting in a type error (that is literally what the error says - couldnt read `info` from `undefined` i.e. `msg.area` was `undefined` & why I said to add `node.warn({"msg.area": msg.area})` just before you access it.

If you think there are places a msg could come through that sometimes does NOT have the `area` property, and that is OK, then you will need to guard against it.

e.g... add a `switch` node before the function that checks `msg.area` is type of object OR in your function:

```auto
if (!Array.isArray(msg.area?.info?.events)) {
   node.error("msg.area.info.events is NOT an array!", msg) // throw catchable error
   return null // halt the flow
}
// original code below
// ...
// ...
return msg

```

---

<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: [1 May 2024 16:37 UTC](https://discourse.nodered.org/t/problems-accessing-an-object/85125/5 "2024-05-01T16:37:25Z")

</div>

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