@DasSurma (wonder if you might wanna help answer this question) Why did TC39 decide to not give new Map() indexes? https://stackoverflow.com/questions/37822141/how-do-you-get-the-key-at-specifc-index-in-javascript-map-object … Right now we have to loop through the Map to get the index of a key.
-
-
Maps (and sets) are indeed unordered. If the order matters, use an array instead.
2 replies 0 retweets 0 likes -
I believe ES sets and maps are ordered in insertion order. It's not explicitly specified, but the specification device uses a List which implies an ordering.
2 replies 0 retweets 2 likes -
If ordering matters, then maps or sets are conceptually the wrong data structure. My mental model is that maps contain a pile of key/value pairs, and sets contain a pile of values. This is also why maps/sets get a `size` rather than a `length`. Length implies an inherent order.
3 replies 0 retweets 0 likes -
While this may be true in general of maps/sets, it's not right for JS Maps/Sets. They work great when ordering matters. And the mental model should be an ordered list of pairs, not a pile.
2 replies 0 retweets 4 likes -
Interesting. Something we should be more explicit/vocal about imo. When I hear Set/Map, I don’t assume ordering.
2 replies 0 retweets 1 like -
That being said, even if they are ordered, does not mean they can be accessed by index, right? So that’s not gonna happen IIUC?
3 replies 0 retweets 0 likes -
I think index access might be going to far (what's the use case?), but having direct access to first and last item, would be very very valuable. I even tried to discuss such feature once: http://mozilla.6506.n7.nabble.com/Retrieving-one-item-from-a-set-td320998.html …
1 reply 0 retweets 1 like -
Mathias, I get ya, but it's not entirely uncommon for Maps/Sets to be ordered. See, for example, these ordered Maps and Sets from Java: https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html … https://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashSet.html …
1 reply 0 retweets 1 like
Thanks, everyone!
ES3 flashbacks still make me weary of relying on insertion order for any kind of non-array object
Let’s discuss non-normative spec clarifications here:https://github.com/tc39/ecma262/issues/1152 …
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.