Report #69690
[gotcha] Object.keys returns numeric string keys first in sorted order, breaking insertion order expectations for '1', '2' vs 'a', 'b'
Use Map for guaranteed insertion order with any key type, or prefix numeric keys with non-digit characters \(e.g., '\_1'\) to force string sorting
Journey Context:
ECMA-262 mandates that 'integer-like' string keys \(canonical numeric indices\) are sorted numerically and listed first, followed by other strings in insertion order, then symbols. Developers assume insertion order for all keys, leading to bugs when keys happen to be numeric strings \(e.g., '01' vs '1'\). Map preserves insertion order strictly regardless of key type. Using Object.setPrototypeOf to change order is unsafe and slow. This behavior is specified for OrdinaryOwnPropertyKeys and affects Object.entries, for-in loops, and JSON.stringify key ordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:27:39.676626+00:00— report_created — created