Syntax
1{{ value | sort }}2{{ value | sort:"desc" }}3{{ value | sort:"name" }}4{{ value | sort:("name", "desc") }}
Usage
- Arrays sort in ascending order by default. Pass
desc to reverse the direction. - Pass a property name to sort objects by that property. A dotted path selects a nested property.
- With both a property and direction, wrap the parameters in parentheses.
- Numbers are compared numerically. Missing and
null property values remain at the end. - Serialized arrays and objects produced by another filter are recognized automatically.
Examples
Open in Playground| Data | 1{2 "values": [3 10,4 2,5 16 ]7}
|
|---|
| Template | 1{{ values | sort }}
|
|---|
| Output | 1[1,2,10]
|
|---|
Open in Playground| Data | 1{2 "values": [3 "a",4 "c",5 "b"6 ]7}
|
|---|
| Template | 1{{ values | sort:"desc" }}
|
|---|
| Output | 1["c","b","a"]
|
|---|
Open in Playground| Data | 1{2 "people": [3 {4 "name": "Lin"5 },6 {7 "name": "Ada"8 }9 ]10}
|
|---|
| Template | 1{{ people | sort:"name" }}
|
|---|
| Output | 1[{"name":"Ada"},{"name":"Lin"}]
|
|---|