Logo

Programming-Idioms

History of Idiom 112 > diff from v20 to v21

Edit summary for version 21 by programming-idioms.org:
[JS] Works with Map, not with hashes.

Version 20

2019-01-24, 12:38:52

Version 21

2019-03-03, 17:14:47

Idiom #112 Iterate over map entries, ordered by keys

Print each key k with its value x from an associative array mymap, in ascending order of k.

Idiom #112 Iterate over map entries, ordered by keys

Print each key k with its value x from an associative array mymap, in ascending order of k.

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
[...mymap.entries()].sort().map(([_, x]) => console.log(x))
Code
[...mymap.entries()].sort().map(([_, x]) => console.log(x))
Comments bubble
We have to spread mymap.entries() because it returns an iterator instead of a list.
Comments bubble
mymap has type Map.
We have to spread mymap.entries() because it returns an iterator instead of a list.
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map