Awee

sort

Sort sorts a slice in ascending or descending order.

Sort sorts a slice in ascending or descending order. Handles strings, numbers, and booleans. Elements of mixed types are grouped by type name.

Input

array

Parameters

#TypeRequired
0stringno

Returns

array

Examples

Sort names alphabetically

Input

names = ["Charlie", "Alice", "Bob"]

Template

{{ names | sort }}

Output

["Alice", "Bob", "Charlie"]

Sort scores from highest to lowest

Input

scores = [72, 95, 88]

Template

{{ scores | sort:'desc' }}

Output

[95, 88, 72]

Sort prices ascending

Input

prices = [9.99, 4.50, 14.00]

Template

{{ prices | sort:'asc' }}

Output

[4.50, 9.99, 14.00]

How is this guide?

On this page