sortBy
sortBy<
T>(params):T[]
Defined in: arrays/sort-by/index.ts:40
Sorts an array of objects by a specified property.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”params
Section titled “params”SortByParams<T>
The parameters object
Returns
Section titled “Returns”T[]
A new sorted array (does not mutate the original)
Example
Section titled “Example”sortBy({ array: [{ age: 30 }, { age: 20 }], key: "age" });// => [{ age: 20 }, { age: 30 }]Keywords
Section titled “Keywords”order by, sort array, arrange, rank
Throws
Section titled “Throws”Error if array is not an array
Throws
Section titled “Throws”Error if key is undefined or null