JavaScript: Sort Map

By Xah Lee. Date: .

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
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

BUY
Ξ£JS
JavaScript in Depth

JavaScript in Depth

Basic Syntax

Value Types

Variable

String

Property

Object and Inheritance

Array

Function

Constructor/Class

Iterable 🌟

Misc