# Populate Array and display through template node

**URL:** https://discourse.nodered.org/t/populate-array-and-display-through-template-node/23188
**Category:** General
**Created:** [16 March 2020 15:46 UTC](https://discourse.nodered.org/t/populate-array-and-display-through-template-node/23188 "2020-03-16T15:46:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Laura](https://avatars.discourse-cdn.com/v4/letter/l/a4c791/32.png) [@Laura](https://discourse.nodered.org/u/Laura)
#### Post date: [16 March 2020 15:46 UTC](https://discourse.nodered.org/t/populate-array-and-display-through-template-node/23188/1 "2020-03-16T15:46:02Z")

</div>

Hi there,

Is it possible to populate an empty array in a function node - in a way that it looks like:  
{array: ["example1", "example2"]}

So far I only managed to do something like this:  
var array=  
var v1 = "";  
var v2 = "";  
if (msg.payload.average \> 4) {  
v1 = " average";  
array.push({v1})  
.. and so on, which creates an array with objects and new key value pairs, in this case v1: "average" and so on, instead of just a list of items/strings:

_array: array[1]_  
_0: object_  
_v1: " average"_  
_1: object_  
_v2: " random"_

Next step, I want to display it in html, for which I have a template node with mustache, but that gives me (with the object array) a list of - object Object.

What I have now is:

 {{#payload}}  
{{#array}}  
- {{.}}
  
{{/array}}  
{{/payload}}  

Any ideas?  
Thank you

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [16 March 2020 15:50 UTC](https://discourse.nodered.org/t/populate-array-and-display-through-template-node/23188/2 "2020-03-16T15:50:15Z")

</div>

Hi, can you please enclose code in backticks? Makes things a lot easier to read.

What you are trying to create is an object rather than an array. However, to populate the array, you don't need to push an object to it as you are doing, only to push the variable:

```auto
array.push(v1)

```

Note the lack of curly brackets.

Oh, and it would be wise not to use a variable called `array` since `Array` is already a reserved native object name.

---

<div class="post-metadata">

### Author: ![Laura](https://avatars.discourse-cdn.com/v4/letter/l/a4c791/32.png) [@Laura](https://discourse.nodered.org/u/Laura)
#### Post date: [16 March 2020 16:22 UTC](https://discourse.nodered.org/t/populate-array-and-display-through-template-node/23188/3 "2020-03-16T16:22:08Z")

</div>

Ah great that solved my issue!  
Thank you for the information.

---

<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 March 2020 16:22 UTC](https://discourse.nodered.org/t/populate-array-and-display-through-template-node/23188/4 "2020-03-30T16:22:15Z")

</div>

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