title: What is the different between for loop and for in loop in javascript
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/242841/javascript-for-in-vs-for">JavaScript for&hellip;in vs for</a>  </p>
  </blockquote>
  
  
  
  <p>I am using a for loop in my function. I use both type of loops, "<code>for in</code>" and "<code>for</code>". Both are producing the same result so I want to know what is the difference between these loops and how to know which loop should be used.
  </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var jam = ['amit','sam','ram','soly']
  for(var i in jam){
  alert(jam[i])
  }
  //for (i=0; i&lt;jam.length; i++) {
  //  jam[i]
  //alert(jam[i].length)
  //}
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  </code></pre>