Skip to content

Function: sortBy()

ts
function sortBy<T>(array, ...iteratees): T[];

Returns a new array sorted by one or more derived keys. 按一个或多个派生键返回排序后的新数组。

Type Parameters

Type ParameterDescription
TThe array item type / 数组元素类型

Parameters

ParameterTypeDescription
arrayreadonly T[]The source array / 源数组
...iterateesSortIteratee<T>[]The sort key selectors / 排序键选择器

Returns

T[]

A new sorted array / 排序后的新数组

Example

ts
sortBy([{ age: 2 }, { age: 1 }], 'age')
// => [{ age: 1 }, { age: 2 }]

Since

1.2.0

Released under the MIT License.