JS: Order of Properties
Order of properties
(new in ECMAScript 2020)
Object's properties are kept in this order:
- First is Integer-like string keys, including
"0"(aka Array index keys), in integer ascending order. - Other String keys, in creation order.
- Last is Symbol keys, in creation order.
const xx = { 2: 1, b: 1, 1: 1, a: 1, 0: 1, "-1": 1, }; console.log(Object.keys(xx)); // [ "0", "1", "2", "b", "a", "-1" ] /* note. 0 1 2 etc are moved to front. -1 is not moved to front. Other string keys, stays in creation order. */