When Object.keys is called in @v8js, no guarantees are made about the order of the keys in the returned array. In practice, they are sorted alphanumerically on the first ten characters of the key. Why ten? Twelve would be nice. Sixteen is also a nice number.
-
-
What makes you say that? All JS engines follow the same order as far as I can tell. The spec has a bug: https://github.com/tc39/ecma262/pull/1242 …pic.twitter.com/UBV0hp3mUF
1 reply 0 retweets 0 likes -
Thanks for that link, that helped me narrow it down. If a key is a String and a valid number it is sorted in ascending numeric order, but only using the first ten characters of the string.pic.twitter.com/BTGxs510QY
2 replies 0 retweets 0 likes -
Sidenote: if your curious why I'd wanted to use long numbers as keys, they are timestamps.
1 reply 0 retweets 1 like -
Also, I didn't mean to impy "just V8". Behavior is same in other browsers, I was in node.js so I referenced V8 in particular. You're right about spec. If it were in there I wouldn't have shouted into the ether.
1 reply 0 retweets 0 likes -
Needed a cup of coffee to digest the GH issue. The point at which they are no longer sorted as ascending array indices is 2^32 (has nothing to do with string length) which make sense. Should that condition be documented in the spec under OrdinaryOwnPropertyKeys?pic.twitter.com/bMtW5TYVKU
1 reply 0 retweets 0 likes -
Exactly! The PR I pointed to fixes the spec to match existing implementations. (Currently, the spec uses integer indices instead of array indices, which essentially moves this cut-off point to a higher number, but no one implements that.)
1 reply 0 retweets 0 likes -
Cool, thank you so much! I should have seen it under 6.1.7 in the spec. How lucky am I that you saw my tweet?
1 reply 0 retweets 1 like
Right back at you! Your comments were helpful; they confirmed that increasing this seemingly arbitrary number limit to a greater number would still be confusing, just in a different way. (I tried to make that point here: https://github.com/tc39/ecma262/pull/1242#issuecomment-399687202 … but it didn’t seem to land.)
-
-
Thought: If users are using numeric keys whose value are greater than 2^32 they are using very large objects or things that must run fast. If switching to integer indices would affect performance then users probably wouldn't want that. Change spec to array indices and let it be.
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
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.