How to render one element of an array in mustache?

Member

by rollin , in category: Javascript , 7 months ago

How to render one element of an array in mustache?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , 7 months ago

@rollin 

To render one element of an array in Mustache, you can access the element directly within the Mustache template by using dot notation.


For example, if you have an array called fruits and you want to render the first element of the array in your template, you can do so like this:

1
2
3
{{ #fruits }} 
    {{.}}
{{ /fruits }}


In this example, {{.}} will render the current element of the fruits array. If you want to render a specific element of the array, you can use the array index like this:

1
2
3
{{ #fruits }} 
    {{ fruits.[0] }}
{{ /fruits }}


This will render the first element of the fruits array. You can replace [0] with any index to render a different element from the array.

Related Threads:

How to render a plain array with mustache.js?
How to render a json template using mustache?
How to render svg element of d3.js using react.js?
How to iterate an array of objects in mustache?
How to render nested data elements using mustache.js?
How to render data in 2d tables via mustache.js?