SORT_BY_KEY_CASE_SENSITIVE

Case-sensitive sort a list of objects by a key

Description

Sorts an array of objects by the values of the given key.

This function performs a case-sensitive sort, meaning that all the upper case letters follow all the lower case letters. This is for advanced use only, because typically you would like to perfrom a case insensitive sort, so unless you have a reason to sort case-sensitively then you should use SORT\_BY\_KEY instead!

If the objects do not contain text or number values under the given key, the sort might not behave as expected.

The third parameter can be used to sort in ascending (default) or descending order.

Function signature

SORT_BY_KEY_CASE_SENSITIVE(list: Array, key: String, order: String = asc) => Array

Parameter

Description

List

List to sort

Key

Key whose value to sort by

Order

Order to sort in ("asc" for ascending, "desc" for descending); defaults to ascending.

Examples

array = [
{
"name": "Ken",
"year": 2010
},
{
"name": "jane",
"year": 1987
},
{
"name": "karen",
"year": 1980
},
{
"name": "John",
"year": 2005
}
]

Formula

Return value

SORT_BY_KEY_CASE_SENSITIVE(array, "name")

[{"name":"John","year":2005},{"name":"Ken","year":2010},{"name":"jane","year":1987},{"name":"karen","year":1980}]

SORT_BY_KEY_CASE_SENSITIVE(array, "name", "desc")

[{"name":"karen","year":1980},{"name":"jane","year":1987},{"name":"Ken","year":2010},{"name":"John","year":2005}]

SORT_BY_KEY_CASE_SENSITIVE(array, "year", "asc")

[{"name":"karen","year":1980},{"name":"jane","year":1987},{"name":"John","year":2005},{"name":"Ken","year":2010}]