Report #36841
[gotcha] Object key insertion order breaks for numeric-like strings \(e.g., '10' sorts before '2'\)
Use Map for insertion-sensitive keys, or prefix numeric IDs with a non-digit string \(e.g., 'id\_123'\) to force lexicographic ordering.
Journey Context:
Since ES2015, objects preserve insertion order, but with a critical exception: keys that are canonical numeric strings \(array indices\) are sorted numerically and appear first. This silently corrupts data structures when using objects as dictionaries with numeric IDs from APIs \(e.g., \{'10': 'a', '2': 'b'\} becomes \['b','a'\]\). Map does not have this special-casing and respects insertion order strictly. Alternatives like sorting keys manually or using arrays of tuples sacrifice lookup speed. The spec mandates this behavior for backward compatibility with array-like objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:18:36.666642+00:00— report_created — created