# How to access array element by index in mustache in template node

**URL:** https://discourse.nodered.org/t/how-to-access-array-element-by-index-in-mustache-in-template-node/26588
**Category:** General
**Created:** [13 May 2020 10:49 UTC](https://discourse.nodered.org/t/how-to-access-array-element-by-index-in-mustache-in-template-node/26588 "2020-05-13T10:49:21Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![PlkMarudny](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plkmarudny/32/28315_2.png) [@PlkMarudny](https://discourse.nodered.org/u/PlkMarudny)
#### Post date: [13 May 2020 11:18 UTC](https://discourse.nodered.org/t/how-to-access-array-element-by-index-in-mustache-in-template-node/26588/3 "2020-05-13T11:18:37Z")

</div>

Well, the flow like below:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/78f7492e5e86801ee2c40ab40d0f01ed4e6b6ce0.png)  
produces the right xml, but this is not the case here, let's skip the xml, simplified flow that shows the issue below, just the nested array value (template.fields[0]) is empty when used in template.

Data:

```auto
{
	"text": "sure",
	"template": {
		"fields": ["some name"]
	}
}

```

Template:

```auto
This works: {{{payload.text}}}, and this not: {{{payload.template.fields[0]}}}!

```

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

```auto
[{"id":"a6885cfc.a7045","type":"inject","z":"e4c94bd5.d53538","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":660,"wires":[["80cdd649.aa6a18"]]},{"id":"80cdd649.aa6a18","type":"change","z":"e4c94bd5.d53538","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{ \t\"text\": \"sure\", \t\"template\": { \t\t\"fields\": [\"some name\"] \t} }","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":660,"wires":[["3befd0f8.c7f39"]]},{"id":"3befd0f8.c7f39","type":"template","z":"e4c94bd5.d53538","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"This works: {{{payload.text}}}, and this not: {{{payload.template.fields[0]}}}!","output":"str","x":480,"y":660,"wires":[["77d87954.9800a8"]]},{"id":"77d87954.9800a8","type":"debug","z":"e4c94bd5.d53538","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":640,"y":660,"wires":[]}]

```

---

_[View the full topic](https://discourse.nodered.org/t/how-to-access-array-element-by-index-in-mustache-in-template-node/26588)._
