title: Endless for loop when using array.length
body: <p>Randomly encountered this. When I store array.length in a variable and apply to the for loop condition using operator &lt;= the loop works fine but when I use array.length with the same operator it becomes infinite. </p>
  
  <pre><code>function map(array, callback) {
    let k =array.length;
     for(let i= 1; i&lt;=k; i++)
       {
        array[i] = callback(array[i]);
       }
  
      return array;
  }
  console.log(map([1, 2, 3], addTwo));
  </code></pre>
  
  <p>This works as expected. But when I use this </p>
  
  <pre><code>   function map(array, callback) {
  
      for(let i= 1; i&lt;=array.length; i++)
       {
  
       array[i] = callback(array[i]);
       }
  
      return array;
      }
       console.log(map([1, 2, 3], addTwo));
  </code></pre>
  
  <p>Of course <code>i=0; i&lt;array.length;</code> is the way to do it. But I am curious what's happening inside it.</p>