Bootstrap FreeKB - Jinja - Return the last element in a list
Jinja - Return the last element in a list

Updated:   |  Jinja articles

last is a Jinja filter that can be used to return the last element in a list. Take for example the following.

{% set fruits=['banana','apples','pineapples', 'grapes'] %}

<br /><br />

Original List: 
{{ fruits }}

<br /><br />

Last Element in List:
{{ fruits | last }}

<br /><br />

Last Element in Sorted List: 
{{ fruits | sort | last }}

 

Something like this should be returned.

Original List: ['banana', 'apples', 'pineapples', 'grapes']

Last Element in List: grapes

Last Element in Sorted List: pineapples

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter fc1c06 in the box below so that we can be sure you are a human.