reverse 将全部字符串或数组反转(从后到前反着写)

将数组中的项目顺序反转。reverse 无法直接反转字符串。

输入

{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}

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

输出



plums, peaches, oranges, apples

虽然 reverse 不能直接用于字符串,但可以通过将字符串拆分成数组、反转数组、再重新组合的方式实现反转。

输入

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

输出

.moT rojaM ot lortnoc dnuorG