Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
783 views
in Technique[技术] by (71.8m points)

javascript - Object.keys order for large numerical indexes?

I have this test:

let obj = {
    "5555555555": 5,
    "4444444444": 4,
    "3333333333": 3,
    "2222222222": 2,
};
console.log(Object.keys(obj));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

None of the major implementations had ever been in line with that particular ES6 specification. But note that exceptions were allowed in EcmaScript 2015-2019 (see this)

Concerning the described behaviour, see for instance the V8 bug report Issue 7874: Respect OrdinaryOwnPropertyKeys order.

While EcmaScript 2016, 2017 and 2018 specifications remained unchanged in this respect, it was decided to align EcmaScript2019 with reality. The section on [[OwnPropertyKeys]]() now reads:

  1. For each own property key P of O that is an array index, in ascending numeric index order, do
    ? ? a. Add P as the last element of keys.

So reference is to array index, which has an unchanged definition (+0 ≤ i < 232?1).

This change occurred in pull request Normative: Use array indices instead of integer indices in OrdinaryOwnPropertyKeys. See also the comments and cross-references there.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...