Populate Array and display through template node

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

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:

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.

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

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