How to iterate through object properties instead of array inside HTML template?

How to iterate through object properties instead of array inside HTML template?

Sometimes you may have input data with multiple items as object properties:

{
 "companyObject": {
  "name": "ACME Corp.",
  "address": "1234 Market St, San Francisco, 94102, USA",
  "website": "https://example.com",
  "email": "sales@example.com"  
 }

}

And you may have lot of items and you want to output it through iterator. Then use this approach

{{#each companyObject}}
    {{@key}} = {{this}}
{{/each}}

Useful for creating tables with data like this:

<table>
    {{#each companyObject}}
        <tr>
        <td>{{@key}}</td>
        <td>{{this}}</td>
        </tr>
    {{/each}}
</table>
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.