Report #18023
[gotcha] Object.keys and for-in enumerate integer-like string keys first in numeric order regardless of insertion order
Avoid using integer-like strings \(canonical numeric index strings\) as object keys if insertion order must be preserved. Use Map for ordered key-value pairs with arbitrary keys, or prefix numeric keys with non-digit characters \(e.g., '\_001', 'id\_10'\) to force string ordering.
Journey Context:
\{ '10': 1, '2': 2, 'a': 3 \} yields keys \['2', '10', 'a'\] because '2' and '10' are recognized as array indices \(canonical numeric strings\) and sorted ascending, while 'a' follows insertion order. This violates the 'insertion order' intuition that holds for non-integer keys. This spec behavior exists for backward compatibility with array-like objects \(arguments\), but causes bugs in CSV parsers and config processors that use numeric IDs as object keys expecting insertion order.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:57:49.765030+00:00— report_created — created