# Any idea how can i access these 2 values inside the array?

**URL:** <https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863>\
**Category:** General\
**Tags:** function-node\
**Created:** [24 January 2025 02:33 UTC](https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863 "2025-01-24T02:33:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaid](https://avatars.discourse-cdn.com/v4/letter/z/e95f7d/32.png) [@zaid](https://discourse.nodered.org/u/zaid)\
**Post date:** [24 January 2025 02:33 UTC](https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863/1 "2025-01-24T02:33:32Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c7b956367feaf9048402d3843d2ea8d419f5a15.png)

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [24 January 2025 02:40 UTC](https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863/2 "2025-01-24T02:40:29Z")

</div>

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/value for 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)

---

<div class="post-metadata">

**Author:** ![zaid](https://avatars.discourse-cdn.com/v4/letter/z/e95f7d/32.png) [@zaid](https://discourse.nodered.org/u/zaid)\
**Post date:** [24 January 2025 03:34 UTC](https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863/3 "2025-01-24T03:34:49Z")

</div>

not sure what's wrong here. I get this error

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/558bcde7136c3abc072fc35f0017cacddc9fe7d5.png)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [24 January 2025 04:27 UTC](https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863/4 "2025-01-24T04:27:18Z")

</div>

If an object key can't be referenced by the dot notation, you can try square brackets  
`gate[0]["_"]` and `gate[1]["_"]`

It looks as though you are working with badly formatted JSON data.  
Where does this data come from & what happens to it in lines 1 - 47 of your function?

If you feed `legData` to a debug node as @Sean-McG hints, you can explore the object structure and use the `Copy path` button to obtain each element path in the appropriate format, dot or square brackets.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 January 2025 09:26 UTC](https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863/5 "2025-01-24T09:26:58Z")

</div>

> [@zaid](#):
>
> not sure what's wrong here

What do you get for the elements when you use the Copy Path feature pointed out in the previous post?

[Edit] Actually it is complaining that `gate` is not defined, assuming that the error is coming from the line you show. Put back the `warn` statement showing `gate` and add another after the next line.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [24 January 2025 15:14 UTC](https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863/6 "2025-01-24T15:14:49Z")

</div>

@zaid NOTE: It's always better to copy actual text rather than screenshots, as it's much easier for people to help if they don't have to type everything out, also less chance of mistakes.

I have tried to recreate your problem in this flow and as you can see it works OK.

So it may be that what you are assigning to gate, doesn't always contain what you think.  
Add back the first warn to show content of gate, then another to show after concatenation.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3afb19321ff3b3bf3adbd9809e147cb5ecdcc954.png)

```auto
[{"id":"f5665d4b4f4387e7","type":"inject","z":"055c98606c931f5b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":350,"y":1660,"wires":[["a36f0795db2a4416"]]},{"id":"a36f0795db2a4416","type":"function","z":"055c98606c931f5b","name":"function 3","func":"let gate = [\n {\n \"_\": \"23A\",\n \"$\": {\n \"wibble\": \"wobble\"\n }\n },\n {\n \"_\": \"23B\",\n \"$\": {\n \"wibble\": \"wobble\"\n }\n }\n]\n\nnode.warn(gate)\nnode.warn(gate[0]._ + \", \" + gate[1]._ );\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":1660,"wires":[[]]}]

```

EDIT: Just looking again at your first post, I see that sometimes its an object and sometimes an array. In this case you will definitely get errors about missing properties !

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/72655e4a70151af0fe32983a0027df8b303061f2.png)

---

<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:** [25 January 2025 13:14 UTC](https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863/7 "2025-01-25T13:14:05Z")

</div>

It looks like you may be using the xml node to create that data from something... maybe try the fastxml node instead as it generally creates easier to work with objects with less arrays within.

---

<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:** [25 April 2025 13:14 UTC](https://discourse.nodered.org/t/any-idea-how-can-i-access-these-2-values-inside-the-array/94863/8 "2025-04-25T13:14:49Z")

</div>

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