Return array item by index in a meteor spacebars template
Asked Answered
F

1

11

I want to access the first item of an array inside a meteor template, I'm using this syntax :

<p>{{array[0]}}</p>

However it doesn't seem like it's working. I don't want to iterate through values using {{#each}}, just pick the first one from the array.

Fumigator answered 3/3, 2015 at 22:58 Comment(0)
P
14

This is just a problem of syntax, the correct one is the following :

<p>{{array.[0]}}</p>

Notice the . dot between the array property and the brackets (array indexing) notation ?

Here is the (hidden) docs for this :

https://github.com/meteor/meteor/wiki/Using-Blaze#dotted-helpers-with-numeric-indices

Phenobarbital answered 3/3, 2015 at 23:15 Comment(2)
it doesn't work anymore I just try with an array of object from database and I got [object Object]Alundum
@saimeunt: Do you know how to do this for a runtime index? #41815519Beyond

© 2022 - 2024 — McMap. All rights reserved.