Suppose I have created a Map object like this Map {"a" => "apple", "b" => "banana"}
:
m = new Map([ ["a", "apple"], ["b", "banana"] ]);
Now I want to reverse it and get Map {"b" => "banana", "a" => "apple"}
I see the only way to do it as follows:
new Map(Array.from(m.entries()).reverse());
which doesn't look neither concise nor straightforward. Is there a nicer way?
function reverseMap(map) { ... }
. Nobody has to know the ugly truth....Map
s actually are ordered only to be deterministic and consistent across engines, not that you order them manually.