Title: How to display each element in an array from Node in HTML?
Tags: html;node.js;express
Question: I'm using express to render a page in my node app and have sent an array to the client-side. I'm wondering how I can display each element as a paragraph in the HTML.

What I tried is below, but it does not work. When my ```results``` array is five elements long, I can see in Safari's Inspect Element that five ```p``` tags are created but they are empty.

Note that the ```results``` array was initiated and populated.

Node:

```const app = express();

app.post('/home', (req, res) =&gt; {
    ...
    // results array gets populated here
    ...

    res.render('home', {results: results});
});

```

HTML:

```<div class="results"&gt;
    {{#each results}}
        <p&gt;{{r}}</p&gt;
    {{/each}}
</div&gt;
```

Comment: @ElliotBlackburn Thanks that worked! And yes, I was using handlebars. Sorry I'm new to Node... Thanks again for your quick reply :)

Comment: @ElliotBlackburn Done!

Comment: That looks like you're using handlebars as your view template engine? If so, you've not define "r" at all. Assuming "results" is an array of objects such as [{val: "hello"}] you can do {{val}} inside your p tag. If it's just a single value, not an object, then try using {{this}}.

Comment: that's great news! I've added this as an answer for future searchers. Would you be able to mark it as correct?

Here is the accepted answer: That looks like you're using handlebars as your view template engine? If so, you've not define ```kimberly65@example.com.

Assuming ```results``` is an array of objects such as ```[{val: "hello"}]``` you can do ```{{val}}``` inside your p tag. If it's just a single value, not an object, then try using ```{{this}}```.

For a complete example:

```<div class="results"&gt;
    {{#each results}}
        <p&gt;{{this}}</p&gt;
    {{/each}}
</div&gt;
```

Or

```<div class="results"&gt;
    {{#each results}}
        <p&gt;{{val}}</p&gt;
    {{/each}}
</div&gt;
```



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:07/31/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<html><node.js><express>', 'Title': 'How to display each element in an array from Node in HTML?', 'ViewCount': 236, 'id': 57298985, 'user_AboutMe': '<p> Micron Technology</p>\n', 'user_AccountId': 10150362.0, 'user_DisplayName': 'viviansplatoon', 'user_Reputation': 148.0, 'user_Views': 404.0, 'user_id': 7497175.0}}