.orderBy(collection, [iteratees=[.identity]], [orders])
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.
Since
4.0.0
Arguments
collection
(Array|Object): The collection to iterate over.[iteratees=[.identity]]
(Array[]|Function[]|Object[]|string[])_: The iteratees to sort by.[orders]
(string[]): The sort orders ofiteratees
.
Returns
(Array): Returns the new sorted array.
Example
var users = [{ 'user': 'fred', 'age': 48 },{ 'user': 'barney', 'age': 34 },{ 'user': 'fred', 'age': 40 },{ 'user': 'barney', 'age': 36 }];// 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]]
当前内容版权归 lodash.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 lodash.com .