Integer Keys Cut The Line
luljs still worksNumber-like object keys always come first, in ascending order.
In 2026: Still works, and it surprises people who expect insertion order. ES2015 pinned the order for Reflect.ownKeys, ES2020 extended it to Object.keys and for-in, and engines did it this way all along: integer-like keys ascending first, then string keys in insertion order. Insert gold, 3, silver, 1 and the keys come back as 1, 3, gold, silver. You cannot pin a numeric key in a chosen spot.
Where it came from: ES2015 specified the order for [[OwnPropertyKeys]]; ES2020 extended it to Object.keys and for-in. Stefan Judis wrote a clear walkthrough.
Stefan Judis ↗
<script>
var medals = {}; medals.gold = 1; medals[3] = 1; medals.silver = 1; medals[1] = 1;
document.write('<p>Inserted in order: <code>gold, 3, silver, 1</code>.</p>');
document.write('<p><code>Object.keys(medals)</code> is <b>' + JSON.stringify(Object.keys(medals)) + '</b></p>');
document.write('<p>Integer-like keys sort to the front, ascending; string keys keep insertion order.</p>');
</script>