liquid / 5.0.0 / filters / first / index.html /

first

Returns the first item of an array.

Input

{{ "Ground control to Major Tom." | split: " " | first }}

Output

Ground

Input

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

{{ my_array.first }}

Output

zebra

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

{% if my_array.first == "zebra" %}
  Here comes a zebra!
{% endif %}

© 2005, 2006 Tobias Luetke
Licensed under the MIT License.
https://shopify.github.io/liquid/filters/first/