 <p>I'll throw an alternative solution into the mix. It is, unapologetically, a huge ugly hack, but gets around a problem.</p> <p>If you have an array called 'theArray' like this</p> <pre><code>100 =&gt; 'a' 200 =&gt; 'b' 300 =&gt; 'c' </code></pre> <p>then replacing</p> <pre><code>for (key in theArray) </code></pre> <p>with </p> <pre><code>for (var i=0; i &lt; theArray.length; i++) </code></pre> <p>does not really help, because the length is '3', but you have keys much higher than the array length. Presumably the keys in such instances have significance, and you want to keep them.</p> <p>The hackish way to fix it is to force JavaScript to treat the keys as strings, not integers. You can do this by doing something quick and dirty like renaming all your keys to</p> <pre><code>"a100" =&gt; 'a' "a200" =&gt; 'b' "a300" =&gt; 'c' </code></pre> <p>Then use some sort of substring function when you want to use the key value later on in your code.</p> <p>Once the keys are treated as strings, all browsers I am aware of will display them in the order they were created, not in any other order.</p> <p>I should add a disclaimer - it's probably better to write your code to avoid this scenario in the first place by not using keys as a means to carry information in this way.</p> <p>eg:</p> <pre><code>0 =&gt; array (100,'a') 1 =&gt; array (200,'b') </code></pre> <p>etc</p> <p>This hack is something I've employed as a quick fix where I didn't want to rewrite a lot of code to not use 'meaningful' integers as keys.</p>