# Array within an object

**URL:** https://discourse.nodered.org/t/array-within-an-object/18051
**Category:** General
**Created:** [17 November 2019 02:20 UTC](https://discourse.nodered.org/t/array-within-an-object/18051 "2019-11-17T02:20:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![scoobyluke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scoobyluke/32/14369_2.png) [@scoobyluke](https://discourse.nodered.org/u/scoobyluke)
#### Post date: [17 November 2019 02:20 UTC](https://discourse.nodered.org/t/array-within-an-object/18051/1 "2019-11-17T02:20:44Z")

</div>

Evening All. A friend suggested I might want to use Node-Red as a solution to problem i'm having but as i'm new to Node-Red, I haven't got much of a clue what i'm doing with it!

We use an online quoting tool called Quotient which can send data out via webhook - Such as this:

```auto
msg.payload : Object
object
event_name: "quote_accepted"
quote_number: 5350
title: "Configure Winman SMTP relay"
quote_url: "url"
from: "someone"
for: "company"
first_sent: "2019-11-13T16:18:21+00:00"
valid_until: "2019-11-27T16:15:00+00:00"
quote_status: "Accepted"
is_archived: false
currency: "GBP"
amounts_are: "Tax Exclusive (Inclusive Total)"
overall_discount: 0
quote_for: object
name_first: "Joe"
name_last: "N"
email: "email@email.com"
company_name: "company"
phone: object
address: object
item_headings: "Configuration of SMTP relay settings on Winman Server"
total_includes_tax: 81
total_excludes_tax: 67.5
discount_amount_includes_tax: 0
discount_amount_excludes_tax: 0
selected_items: array[1]
0: object
item_code: ""
heading: "Configuration of SMTP relay settings on Winman Server"
description: "1 hour support time (remote)"

accepted: object
accepted_on_behalf: false
accepted_on_behalf_who: ""
order_number: "PO-0173617"
comments: ""
when: "2019-11-13T16:22:28+00:00"
by: object

```

I've got Node-Red to receive the webhook data which is then sent on to a temple file:

```auto
<html>
 <head>
 </head>   
   <body>
       <h1>Quote Accepted</h1>
      <p><b>Quote Title:</b> {{payload.title}}</p>
      <p><b>Organisation:</b> {{payload.for}}</p>
      <p><b>test:</b> {{payload.selected_items[0].heading}}</p>
      <table>
    <tr ng-repeat="(key, value) in payload">
        <td>{{key}}</td>
        <td>{{value}}</td>
    </tr>
</table>
</body> 
</html>

 I can access properties such as {{payload.title}} and {{payload.for}} but I can't seem to assess properties contained within the selected_items: array[1]. Ideally i would like to use ng-repeat to list any items in this array. 

Any help would be much appreciated. 

Thanks in advance,

Luke
```

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [17 November 2019 08:27 UTC](https://discourse.nodered.org/t/array-within-an-object/18051/2 "2019-11-17T08:27:45Z")

</div>

The (not ui) template uses mustache not angular so array index is just ...items.0.heading... And you use {{#property}} .... {{/property}} to create an iteration

---

<div class="post-metadata">

### Author: ![scoobyluke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scoobyluke/32/14369_2.png) [@scoobyluke](https://discourse.nodered.org/u/scoobyluke)
#### Post date: [17 November 2019 10:38 UTC](https://discourse.nodered.org/t/array-within-an-object/18051/3 "2019-11-17T10:38:28Z")

</div>

Hi Dceejay,

Thanks for getting back to me so quickly. When you say 'not ui' templete, what do you mean? I used the template node withing the UI to create the HTML template.

Thanks again for your help,

Luke

---

<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: [17 November 2019 10:59 UTC](https://discourse.nodered.org/t/array-within-an-object/18051/4 "2019-11-17T10:59:34Z")

</div>

There are two template nodes - the "not ui" `template` node can be found in the "Functions' group of templates. The `ui-template` can be found in the "Dashboard' Template group.

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

---

<div class="post-metadata">

### Author: ![scoobyluke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scoobyluke/32/14369_2.png) [@scoobyluke](https://discourse.nodered.org/u/scoobyluke)
#### Post date: [17 November 2019 22:41 UTC](https://discourse.nodered.org/t/array-within-an-object/18051/5 "2019-11-17T22:41:12Z")

</div>

Thanks for explanation Zenofmud - makes perfect sense now however I still can't seem to access the selected\_items array within the payload:

```auto
msg.payload : Object
object
event_name: "quote_accepted"
quote_number: 5350
title: "Configure Winman SMTP relay"
item_headings: "Configuration of SMTP relay settings on Winman Server"
selected_items: array[1]
0: object
item_code: ""
heading: "Configuration of SMTP relay settings on Winman Server"
description: "1 hour support time (remote)"
accepted: object
accepted_on_behalf: false
accepted_on_behalf_who: ""
order_number: "PO-0173617"
comments: ""
when: "2019-11-13T16:22:28+00:00"
by: object

```

I assume it should be {{payload.selected\_items.1}} if referenced directly but that doesn't seem to work.

Sorry if i'm being dim!

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [17 November 2019 22:52 UTC](https://discourse.nodered.org/t/array-within-an-object/18051/6 "2019-11-17T22:52:02Z")

</div>

Try `{{payload.selected_items[0]}}`

To visualize an array, see it as a "box" `[]` that contains values and are indexed. Array indexes are (usually) zero based, the first item is 0. If you want the first item of items, use `items[0]`

Although in this case your "value" in the array is an object. You will need to determine the properties of the object.

---

<div class="post-metadata">

### Author: ![scoobyluke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scoobyluke/32/14369_2.png) [@scoobyluke](https://discourse.nodered.org/u/scoobyluke)
#### Post date: [19 November 2019 21:21 UTC](https://discourse.nodered.org/t/array-within-an-object/18051/7 "2019-11-19T21:21:15Z")

</div>

Thank you for all your help. It now works.
