# How to use msg.payload as an index in a change node?

**URL:** <https://discourse.nodered.org/t/how-to-use-msg-payload-as-an-index-in-a-change-node/4215>\
**Category:** General\
**Created:** [23 October 2018 11:30 UTC](https://discourse.nodered.org/t/how-to-use-msg-payload-as-an-index-in-a-change-node/4215 "2018-10-23T11:30:25Z")\
**Posts on this page:** 3\
**Page:** 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:** [23 October 2018 11:30 UTC](https://discourse.nodered.org/t/how-to-use-msg-payload-as-an-index-in-a-change-node/4215/1 "2018-10-23T11:30:25Z")

</div>

(This is a hallowen project)  
In an change node, I've built a flow object 'flow.wolf' that is an array

![21%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cb1e8e8f8845e41faa57c9b0dc43e93f4c1f0bb0.png)

I then pick a random number between 0 and 2 using the random node so msg.payload now contains a number 0, 1 or 2. I feed this to another change node and I want to use msg.payload as the index of the flow object but I can't get it to work. In the change node I have:

![57%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/69c9affae0d571daa25f62f2faabe8cf8317f905.png)

But msg.audioURI is not being set. ???

Here is the flow:

```auto
[{"id":"86d7e7ad.263bc8","type":"change","z":"df3238f6.f811b","name":"","rules":[{"t":"set","p":"wolf","pt":"flow","to":"{\"howl\":[\"wolf_howlin.wav\",\"wolf2.wav\",\"wolf3.wav\"]}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":130,"y":140,"wires":[["4ebe550d.f715b4"]]},{"id":"f8b66d0a.a6708","type":"inject","z":"df3238f6.f811b","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":100,"wires":[["86d7e7ad.263bc8"]]},{"id":"4ebe550d.f715b4","type":"random","z":"df3238f6.f811b","name":"","low":"0","high":"2","inte":"true","property":"payload","x":120,"y":180,"wires":[["c787a992.59da4"]]},{"id":"c787a992.59da4","type":"change","z":"df3238f6.f811b","name":"Set audioURI to random sound","rules":[{"t":"set","p":"audioURI","pt":"msg","to":"wolf.howl[msg.payload]","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":220,"wires":[["7726d7b9.dc03f"]]},{"id":"7726d7b9.dc03f","type":"debug","z":"df3238f6.f811b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":110,"y":260,"wires":[]}]
'''
```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [23 October 2018 11:42 UTC](https://discourse.nodered.org/t/how-to-use-msg-payload-as-an-index-in-a-change-node/4215/2 "2018-10-23T11:42:49Z")

</div>

The flow/global types of the TypedInput field doesn't support referencing message properties. To do that, you have to use the Expression type with some JSONata:

```
$flowContext('wolf').howl[$$.payload]
```

---

<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:** [23 October 2018 13:20 UTC](https://discourse.nodered.org/t/how-to-use-msg-payload-as-an-index-in-a-change-node/4215/3 "2018-10-23T13:20:24Z")

</div>

> [@knolleary](#):
>
> $flowContext('wolf').howl[$$.payload]

Excellent! Thanks! (and why didn't I think about using JSONata...sigh)
