const users = [
{ user: 'foo', age: 24 },
{ user: 'bar', age: 7 },
{ user: 'foo', age: 8 },
{ user: 'bar', age: 29 },
];
sortBy(users, ['user', 'age']);
sortBy(users, [obj => obj.user, 'age']);
// results will be:
// [
// { user : 'bar', age: 7 },
// { user : 'bar', age: 29 },
// { user : 'foo', age: 8 },
// { user : 'foo', age: 24 },
// ]
Sorts an array of (objects | strings | numbers) based on the given
accords.The function returns the array of (objects | strings | numbers) sorted in ascending order. If two (objects | strings | numbers) the same value for the current accordion, it uses the next accordion to determine their order.
根据给定的
accords对 (objects | strings | numbers) 数组进行排序。该函数返回按升序排序的 (objects | strings | numbers) 数组。 若两个 (objects | strings | numbers) 在当前排序依据上具有相同值,则使用下一个排序依据来确定它们的顺序。