Report #11481
[gotcha] Object.keys sorts integer-like string keys numerically before other keys regardless of insertion order
Use \`Map\` for guaranteed insertion-order collection; or prefix numeric keys with a non-digit \(e.g., \`"id\_123"\`\) when using plain objects to prevent re-ordering; avoid relying on key order for numeric identifiers.
Journey Context:
While ES2015 guaranteed insertion order for string keys, the spec carves out an exception: keys that are "array indices" \(canonical numeric strings\) are sorted ascending and listed before all other keys. This causes API responses keyed by numeric IDs \(e.g., \`\{10: ..., 2: ...\}\`\) to iterate as \`2\` then \`10\`, breaking pagination UIs that expect creation order. Developers often choose objects over Maps for JSON serialization convenience, not realizing the reordering rule. \`Map\` is the only structure that truly preserves insertion order for all key types.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:23:40.446679+00:00— report_created — created