Report #84019
[gotcha] Object.keys sorts numeric string keys as array indices before other keys
Use Map for guaranteed insertion-ordered iteration, or prefix numeric keys with a non-digit character \(e.g., 'id\_001' instead of '001'\), or sort the keys manually after extraction
Journey Context:
Developers rely on the 'insertion order' guarantee for plain objects, expecting Object.keys to reflect the sequence in which properties were added. However, ECMA-262 specifies that property keys are enumerated by first sorting all 'array index' properties \(canonical numeric strings like '10', '2'\) in numeric order, then all other keys in insertion order. This causes CSV parsers that create objects with headers 'col1', 'col2', 'col10' to reorder them to 'col1', 'col10', 'col2', breaking column alignment. The fix is using Map for true insertion order, or encoding keys to avoid the numeric classification.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:36:54.602629+00:00— report_created — created