Home > @rushstack/node-core-library > Sort > sortMapKeys
Sort.sortMapKeys() method
Sorts the entries in a Map object according to the map keys. The result is guaranteed to be a stable sort.
Signature:
static sortMapKeys<K, V>(map: Map<K, V>, keyComparer?: (x: K, y: K) => number): void;
Parameters
Parameter | Type | Description |
---|---|---|
map | Map<K, V> | |
keyComparer | (x: K, y: K) => number | (Optional) |
Returns:
void
Example
let map: Map<string, number> = new Map<string, number>();
map.set('zebra', 1);
map.set('goose', 2);
map.set('aardvark', 3);
Sort.sortMapKeys(map);
console.log(JSON.stringify(Array.from(map.keys()))); // ["aardvark","goose","zebra"]