# Extract array from Global context

**URL:** <https://discourse.nodered.org/t/extract-array-from-global-context/24961>\
**Category:** General\
**Created:** [16 April 2020 17:32 UTC](https://discourse.nodered.org/t/extract-array-from-global-context/24961 "2020-04-16T17:32:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [16 April 2020 17:32 UTC](https://discourse.nodered.org/t/extract-array-from-global-context/24961/1 "2020-04-16T17:32:06Z")

</div>

I have a problem extracting an array from a Global variable that is an array of arrays.  
I want to use a calculated index instead of a fixed index. this is in a JsoNATA expression in a change node:

$globalContext("rfcodes")[0] works  
$globalContext("rfcodes")[payload-1] does not

rfcodes looks like this:

```auto
array[2]
0: array[4]
0: 9710
1: 250
2: 870
3: "#454551"
1: array[4]
0: 9710
1: 250
2: 870
3: "#454554"

```

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [16 April 2020 18:05 UTC](https://discourse.nodered.org/t/extract-array-from-global-context/24961/2 "2020-04-16T18:05:02Z")

</div>

The answer was worth two Dollars 🙂  
$globalContext("rfcodes")[$$.payload-1]

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [16 April 2020 19:22 UTC](https://discourse.nodered.org/t/extract-array-from-global-context/24961/3 "2020-04-16T19:22:02Z")

</div>

Wait!! Who got the two dollars? 🤣

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [16 April 2020 19:41 UTC](https://discourse.nodered.org/t/extract-array-from-global-context/24961/4 "2020-04-16T19:41:40Z")

</div>

From left pocket to right 😄

---

<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:** [30 April 2020 19:41 UTC](https://discourse.nodered.org/t/extract-array-from-global-context/24961/5 "2020-04-30T19:41:46Z")

</div>

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