// 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及其对应的排序方向对 (对象 | 字符串 | 数字) 数组进行排序。该函数返回按相应顺序方向排序的 (对象 | 字符串 | 数字) 数组。 若两个 (对象 | 字符串 | 数字) 在当前排序依据上具有相同值,则使用下一个排序依据来确定它们的顺序。 若排序依据的数量少于排序方向的数量,则剩余排序依据将沿用最后一个指定的排序方向。