# How to use a message variable to navigate an array that is also a message variable, in a change node?

**URL:** <https://discourse.nodered.org/t/how-to-use-a-message-variable-to-navigate-an-array-that-is-also-a-message-variable-in-a-change-node/65005>\
**Category:** General\
**Created:** [12 July 2022 14:17 UTC](https://discourse.nodered.org/t/how-to-use-a-message-variable-to-navigate-an-array-that-is-also-a-message-variable-in-a-change-node/65005 "2022-07-12T14:17:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [12 July 2022 14:17 UTC](https://discourse.nodered.org/t/how-to-use-a-message-variable-to-navigate-an-array-that-is-also-a-message-variable-in-a-change-node/65005/1 "2022-07-12T14:17:14Z")

</div>

Hey there,

I'm struggling trying to use a message variable to navigate an array that is also a message variable, in a change node, as follows:

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

I tried the following, but nothing works:  
msg.months[msg.index]  
msg.months[index]  
msg.months[$.index]  
msg.months[$$.index]

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [12 July 2022 14:21 UTC](https://discourse.nodered.org/t/how-to-use-a-message-variable-to-navigate-an-array-that-is-also-a-message-variable-in-a-change-node/65005/3 "2022-07-12T14:21:25Z")

</div>

Ah!

Just got it working by using twice the $$ as follows:

$$.months[$$.index]

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

---

<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:** [12 July 2022 15:27 UTC](https://discourse.nodered.org/t/how-to-use-a-message-variable-to-navigate-an-array-that-is-also-a-message-variable-in-a-change-node/65005/5 "2022-07-12T15:27:20Z")

</div>

There is no need for JSONata in simple cases like this, you can use array syntax...

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

_(requires newish version of node-red)_

---

<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:** [26 July 2022 15:28 UTC](https://discourse.nodered.org/t/how-to-use-a-message-variable-to-navigate-an-array-that-is-also-a-message-variable-in-a-change-node/65005/6 "2022-07-26T15:28:18Z")

</div>

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