Files
liquid/_filters/last.md
2019-09-11 10:46:41 -04:00

843 B

title, description
title description
last Liquid filter that returns the last item of an array.

Returns the last item of an array.

Input

```liquid {% raw %} {{ "Ground control to Major Tom." | split: " " | last }} {% endraw %} ```

Output

```text {{ "Ground control to Major Tom." | split: " " | last }} ```

Input

```liquid {% raw %} {% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}

{{ my_array.last }} {% endraw %}


<p class="code-label">Output</p>
```text
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}

{{ my_array.last }}

You can use last with dot notation when you need to use the filter inside a tag:

{% raw %}
{% if my_array.last == "tiger" %}
  There goes a tiger!
{% endif %}
{% endraw %}