sort_natural

v8.4.0

Sorts items in an array in case-insensitive order.

Input

1
2
3
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}

{{ my_array | sort_natural | join: ", " }}

Output

1
2
3


giraffe, octopus, Sally Snake, zebra

An optional argument specifies which property of the array’s items to use for sorting.

1
2
3
4
{% assign products_by_company = collection.products | sort_natural: "company" %}
{% for product in products_by_company %}
<h4>{{ product.title }}</h4>
{% endfor %}