Accessing Array item by index in template #158

rlightner opened this Issue Jan 24, 2012 · 6 comments


None yet

5 participants

<li lat="{{ll[0]}}" lng="{{ll[1]}}">{{name}}</li>

ll is a two item array [47, -122]

Is this valid or do I have to write a function to extra the item at index I want?



{{ll.0}} and {{ll.1}} will work in most mustache implementations... haven't tried it in mustache.js though :)


Thanks, I'll give that a try.


Indeed, if you're using 0.5 (currently on master) you can do something like this:

mustache.render("{{a.0}}", {a: ['hi']})
=> 'hi'
@mjackson mjackson closed this Jan 30, 2012
P48L0 commented May 9, 2012

this should be on the documentation, it's very usefull. You can even do this if you are int he current item: {{0}}

piazera commented Dec 18, 2013

how can I use another {{variable}} as the index?
i.e. {{my_array.{{my_index}}}}


@piazera You can't. Mustache feels like that's one step too far over the "logic-less" line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment