reverse
array | reverse
Reverses the order of the items in an array.
Original order:
{{ collection.products | map: 'title' | join: ', ' }}
Reverse order:
{{ collection.products | reverse | map: 'title' | join: ', ' }}
Code
Original order:
{{ collection.products | map: 'title' | join: ', ' }}
Reverse order:
{{ collection.products | reverse | map: 'title' | join: ', ' }}Data
{
"collection": {
"products": [
{
"title": "Draught of Immortality"
},
{
"title": "Glacier ice"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
}
]
}
}Output
Original order:
Draught of Immortality, Glacier ice, Health potion, Invisibility potion
Reverse order:
Invisibility potion, Health potion, Glacier ice, Draught of Immortality
Output
Original order:
Draught of Immortality, Glacier ice, Health potion, Invisibility potion
Reverse order:
Invisibility potion, Health potion, Glacier ice, Draught of ImmortalityAnchor to Reversing strings
Reversing strings
You can't use the reverse filter on strings directly. However, you can use the split filter to create an array of characters in the string, reverse that array, and then use the join filter to combine them again.
{{ collection.title | split: '' | reverse | join: '' }}
Code
{{ collection.title | split: '' | reverse | join: '' }}Data
{
"collection": {
"title": "Sale potions"
}
}Output
snoitop elaS
Output
snoitop elaSWas this page helpful?