mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
946 B
946 B
title, description
| title | description |
|---|---|
| reverse | Liquid filter that reverses an array, or a string converted to an array. |
Reverses the order of the items in an array. reverse cannot reverse a string.
Input
```liquid {%- raw -%} {% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}{{ my_array | reverse | join: ", " }} {% endraw %}
<p class="code-label">Output</p>
```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | reverse | join: ", " }}
Although reverse cannot be used directly on a string, you can split a string into an array, reverse the array, and rejoin it by chaining together filters.
Input
```liquid {%- raw -%} {{ "Ground control to Major Tom." | split: "" | reverse | join: "" }} {% endraw %} ```Output
```text {{ "Ground control to Major Tom." | split: "" | reverse | join: "" }} ```