Home > @infiniteobjects/core-library-web > Sort > sortBy
Warning: This API is now obsolete.
Use Arrays.sortBy() instead.
Sorts the array according to a key which is obtained from the array elements. The result is guaranteed to be a stable sort.
Signature:
static sortBy<T>(array: T[], keySelector: (element: T) => any, comparer?: (x: any, y: any) => number): void;
Parameter | Type | Description |
---|---|---|
array | T[] | |
keySelector | (element: T) => any | |
comparer | (x: any, y: any) => number | (Optional) |
Returns:
void
This method changes the array in place
let array: string[] = [ 'aaa', 'bb', 'c' ];
Sort.sortBy(array, x => x.length); // [ 'c', 'bb', 'aaa' ]