reverse反转数组中项目的顺序

reverse反转数组中项目的顺序

ZKEASOFT August 28, 2018


reverse

reverse反转数组中项目的顺序。 reverse不能直接反转字符串。

输入

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

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

输出

plums, peaches, oranges, apples

reverse字符串

reverse不能反转字符串,但你可以先将字符串拆分成数组,再reverse它,最后把它们join起来:

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

输出

.moT rojaM ot lortnoc dnuorG

微信公众号