JavaScript ES6 Map Example:
const map = new Map();
map.set('first', ['1', '2']);
map.set('second', ['abc', 'def']);
map.set('_third', []);
map.set(')(*', []);
map.set('he__e', []);
console.log(map);
One important thing to note about a Map object is that it iterates its elements in insertion order.
I decided to sort the map in ascending order as shown below:
var mapAsc = new Map([...map.entries()].sort());
console.log(mapAsc)
However, the output seems unexpected:
0: {")(*" => Array(0)}
1: {"_third" => Array(0)}
2: {"first" => Array(2)}
3: {"he__e" => Array(0)}
4: {"second" => Array(2)}
Why does the index '3' contain special characters? I would like the output to be as follows:
0: {")(*" => Array(0)}
1: {"_third" => Array(0)}
2: {"he__e" => Array(0)}
3: {"first" => Array(2)}
4: {"second" => Array(2)}