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 %}