JS: Sort Map 🚀

By Xah Lee. Date: . Last updated: .

Here is a function that sorts a map object by the key's values as numbers.

/*
returns a new map sorted by the vals compared as numbers
URL http://xahlee.info/js/js_map_sort.html
Version 2021-05-08
*/
const xah_sort_map_by_val =
  ((x) => new Map([...x.entries()].sort((([_, x], [_2, y]) => y - x))));

JavaScript, Map Object

BUY ΣJS JavaScript in Depth