Why not run my javascript function?
<p>I'm trying to run this code and does not work</p>

<pre><code>var  months=new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "Octuber", "November","Dicember");

 function getIndex(ar){
     for (var i=0; i&lt;ar.length; i++){
         ar[ar[i]]=ar[i];
         return i;  
     }
     return -1;
 }
 alert(getIndex(months["May"])); // error
</code></pre>

<p>But the below code run ok</p>

<pre><code>for (var i=0; i&lt;months.length; i++){
    months[months[i]]=months[i];
}
alert(months["May"]) ​// run ok​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
</code></pre>
