sort

对数组中的项目进行区分大小写的排序。

输入

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

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

输出



Sally Snake, giraffe, octopus, zebra

一个可选的参数指定了用于排序的数组项的哪个属性。

{% assign products_by_price = collection.products | sort: "price" %}
{% for product in products_by_price %}
  <h4>{{ product.title }}</h4>
{% endfor %}