More built-in methods for Map

Why does the Map class not have many built-in methods like in arrays?

Considering Map is an ordered structure, could we not have methods like Map.prototype.find(), Map.prototype.sort(), Map.prototype.filter(), etc? Mostly the methods that are present in an array.

A Map is not an ordered structure! Sure, it does have a well-defined iteration order to guarantee consistency between implementations and make iteration predictable and reproducible, but it is fundamentally an unordered collection. You cannot access it by index, you cannot get the index of an element, you cannot get the next element after or before another.

You can use the methods from the iterator helpers proposal on the .keys(), .values() and .entries() iterators, and there is also the collection methods proposal.

1 Like

The collection methods proposal was exactly what I was looking for. Thanks!

Also, I didn't know Maps couldn't be considered an ordered structure, considering they store elements in the insertion order.