This method is like sortBy except that it allows specifying the sort
orders of the iteratees to sort by. If orders is unspecified, all values
are sorted in ascending order. Otherwise, specify an order of "desc" for
descending or "asc" for ascending sort order of corresponding values.
You may also specify a compare function for an order.
// Sort by `user` in ascending order and by `age` in descending order. orderBy(users, ['user', 'age'], ['asc', 'desc']) // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
// Sort by `user` then by `age` using custom compare functions for each orderBy(users, ['user', 'age'], [ (a, b) =>a.localeCompare(b, 'de', { sensitivity:'base' }), (a, b) =>a - b, ])
This method is like
sortBy
except that it allows specifying the sort orders of the iteratees to sort by. Iforders
is unspecified, all values are sorted in ascending order. Otherwise, specify an order of "desc" for descending or "asc" for ascending sort order of corresponding values. You may also specify a compare function for an order.Since
5.10.0
See
[[reverse]]
Example