sort
Sorts a copy of a slice in the named direction, 'asc' or 'desc'; any other direction is an error.
The original slice is left unmodified, and an empty slice comes back untouched.
InputArgumentsReturns
Source[]anystring[]any[]anyno arguments[]anyBasicSource
Sorts a copy of a slice in the named direction, here descending.
Given
{"scores": [72, 95, 88]}Template
{{ scores | sort:'desc' }}Result
[
95,
88,
72
]StringsSource
Sorts strings in reverse alphabetical order.
Given
{"names": ["Alice", "Charlie", "Bob"]}Template
{{ names | sort:'desc' }}Result
[
"Charlie",
"Bob",
"Alice"
]BasicSource
Sorts a slice ascending, the default direction when none is given.
Given
{"names": ["Charlie", "Alice", "Bob"]}Template
{{ names | sort }}Result
[
"Alice",
"Bob",
"Charlie"
]NumbersSource
Sorts numbers numerically rather than as text.
Given
{"scores": [30, 4, 200, 1]}Template
{{ scores | sort }}Result
[
1,
4,
30,
200
]