JavaScript: Sort Map

By Xah Lee. Date: .

Here's 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
JS: Sort Map 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

βˆ‘ JS in Depth
XAH Β BUY NOW

JS in Depth

JS Obj Ref

DOM


JS in Depth

Basic Syntax

Value Types

Variable

String

Function

Property

Object and Inheritance

Array

Constructor/Class

Iterable 🌟

Misc