# Change Node - access Array Object

**URL:** <https://discourse.nodered.org/t/change-node-access-array-object/49067>\
**Category:** General\
**Created:** [29 July 2021 08:06 UTC](https://discourse.nodered.org/t/change-node-access-array-object/49067 "2021-07-29T08:06:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [29 July 2021 08:06 UTC](https://discourse.nodered.org/t/change-node-access-array-object/49067/1 "2021-07-29T08:06:54Z")

</div>

Guys,

I have a global Object with array elements in there - the number of elements varies dependant on the time.

Is there a way in a Change Node to access the last element in an array ??

I am essentially trying to grab some dynamic info and put it out to a log file.

Here is a picture of the object/array in question

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

Currently Amber.CurrentBids has 4 elements in the array - but at the 1/2 hour and hour this gets reset to 0 and then the elements filled every 5 minutes.

So in a change node i want to set (say) msg.Amber5MinBid to global.Amber.CurrentBids."Last Array Value"

Anyway to do this or is it better with a function node ?

Craig

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [29 July 2021 08:21 UTC](https://discourse.nodered.org/t/change-node-access-array-object/49067/2 "2021-07-29T08:21:43Z")

</div>

I have just done some messing around with jsonata instead of the global set

$globalContext("Amber.CurrentBids".[-1])

Appears from online reading that it should do it but does not

Also tried

$globalContext("Amber.CurrentBids.[-1]")

No good either

but if i try

$globalContext("Amber.CurrentBids.0")

that works fine.

So i am wondering if we do not support this in NR in Jsonata ?

Craig

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [29 July 2021 08:24 UTC](https://discourse.nodered.org/t/change-node-access-array-object/49067/3 "2021-07-29T08:24:14Z")

</div>

what about  
`$globalContext("Amber.CurrentBids")[-1]`

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [29 July 2021 08:47 UTC](https://discourse.nodered.org/t/change-node-access-array-object/49067/4 "2021-07-29T08:47:38Z")

</div>

Yep that got it - thanks for the pointer !!

Craig

---

<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:** [12 August 2021 08:47 UTC](https://discourse.nodered.org/t/change-node-access-array-object/49067/5 "2021-08-12T08:47:49Z")

</div>

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