Reputation: 1073
I would like to access the second value of an array in Nunjucks. Is this possible? I've read through the documentation but I can't seem to work it out.
{{ array | first }}
and {{ array | last }}
work, but is it possible to do something like {{ array | second }}
?
Upvotes: 2
Views: 2397
Reputation: 29987
Just to solidify Aikon Mogwai's comment, you can do this with bracket notation on the array itself like this:
var data = { arr: ['a','b','c'] }
var templateStr = "{{ arr[1] }}"
var result = nunjucks.renderString(templateStr, data) // 'b'
Upvotes: 2