Quick answer: Construct 3 Dictionary For Each key iterating in seemingly random order? Dictionary doesn’t guarantee insertion order — some browsers do (string keys), some don’t (numeric).
A leaderboard built on a Dictionary keyed by player name prints scores in scrambled order.
Order Is Implementation-Defined
Dictionary maps to a JS object internally. Browsers’ object iteration order varies based on key type and history. Don’t rely on insertion order.
Sort via Array
Push the dictionary’s keys into an Array. Sort the array. Iterate the array, looking up each key in the dictionary. Deterministic order regardless of dictionary internals.
Composite Keys
For complex sort (by score then name), build sortable composite keys (zero-padded score + name) and sort lexicographically.
Stable Sort
JS sort is stable in modern browsers. For ties, secondary key inside sort comparator handles tiebreaking.
Verifying
Iteration order is consistent across browsers, sessions, and platforms. Sorted output matches expected order.
“Dictionary iteration isn’t ordered. Sort keys via Array for predictable output.”
If order matters, your data isn’t really a dictionary — consider an Array of objects from the start.