last
array | last
Returns the last item in an array.
{%- assign last_product = collection.products | last -%}
{{ last_product.title }}
{%- assign last_product = collection.products | last -%}
{{ last_product.title }}
{
"collection": {
"products": [
{
"title": "Blue Mountain Flower"
},
{
"title": "Charcoal"
},
{
"title": "Crocodile tears"
},
{
"title": "Dandelion milk"
},
{
"title": "Draught of Immortality"
},
{
"title": "Dried chamomile"
},
{
"title": "Forest mushroom"
},
{
"title": "Gift Card"
},
{
"title": "Glacier ice"
},
{
"title": "Ground mandrake root"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
},
{
"title": "Komodo dragon scale"
},
{
"title": "Love Potion"
},
{
"title": "Mana potion"
},
{
"title": "Potion beats"
},
{
"title": "Potion bottle"
},
{
"title": "Viper venom"
},
{
"title": "Whole bloodroot"
}
]
}
}
Output
Whole bloodroot
Anchor to Dot notation
Dot notation
You can use the last
filter with dot notation when you need to use it inside a tag or object output.
{{ collection.products.last.title }}
{{ collection.products.last.title }}
{
"collection": {
"products": [
{
"title": "Blue Mountain Flower"
},
{
"title": "Charcoal"
},
{
"title": "Crocodile tears"
},
{
"title": "Dandelion milk"
},
{
"title": "Draught of Immortality"
},
{
"title": "Dried chamomile"
},
{
"title": "Forest mushroom"
},
{
"title": "Gift Card"
},
{
"title": "Glacier ice"
},
{
"title": "Ground mandrake root"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
},
{
"title": "Komodo dragon scale"
},
{
"title": "Love Potion"
},
{
"title": "Mana potion"
},
{
"title": "Potion beats"
},
{
"title": "Potion bottle"
},
{
"title": "Viper venom"
},
{
"title": "Whole bloodroot"
}
]
}
}
Output
Whole bloodroot
Was this page helpful?