The type of elements in the array / 数组元素的类型
The array of items to sort. 要排序的数组
The sorting criteria: keys of T or functions that extract a sort key from each item. 排序依据:T 的键名或从每个元素提取排序键的函数
The sort direction for each criterion. If fewer orders than accords, the last order is reused. Defaults to 'asc'. 每个排序依据的排序方向。若排序方向少于排序依据,则复用最后一个方向。默认 'asc'
A new sorted array (the original array is not mutated). 排序后的新数组(原数组不变)
// Sort an array of objects by 'user' in ascending order and 'age' in descending order.
const users = [
{ user: 'fred', age: 48 },
{ user: 'barney', age: 34 },
{ user: 'fred', age: 40 },
{ user: 'barney', age: 36 },
];
const result = orderBy(users, [obj => obj.user, 'age'], ['asc', 'desc']);
// result will be:
// [
// { user: 'barney', age: 36 },
// { user: 'barney', age: 34 },
// { user: 'fred', age: 48 },
// { user: 'fred', age: 40 },
// ]
Sorts an array of (objects | strings | numbers) based on the given
accordsand their corresponding order directions.The function returns the array of (objects | strings | numbers) sorted in corresponding order directions. If two objects have the same value for the current accordion, it uses the next accordion to determine their order. If the number of orders is less than the number of accord, it uses the last order for the rest of the accord.
根据给定的
accords及其对应的排序方向对 (对象 | 字符串 | 数字) 数组进行排序。该函数返回按相应顺序方向排序的 (对象 | 字符串 | 数字) 数组。 若两个 (对象 | 字符串 | 数字) 在当前排序依据上具有相同值,则使用下一个排序依据来确定它们的顺序。 若排序依据的数量少于排序方向的数量,则剩余排序依据将沿用最后一个指定的排序方向。