Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return array item by index in a meteor spacebars template

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.

like image 838
Marty Cochrane Avatar asked Mar 03 '15 22:03

Marty Cochrane


1 Answers

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

like image 105
saimeunt Avatar answered Nov 09 '22 02:11

saimeunt