title: Javascript array.forEach Scope?
body: <p>The console.log on line 9 shows</p>
  
  <p>{ 'count' : 1111111 , 'average' : 2222222 , 'total' : 3333333 } </p>
  
  <p>for all 3 array elements even though the loop that makes those changes has not run yet. How is this possible?</p>
  
  <pre><code>function test11(){
  
      var test = [
          { 'count' : 1 , 'average' : 2 , 'total' : 3 } ,
          { 'count' : 10 , 'average' : 20 , 'total' : 30 } , 
          { 'count' : 100 , 'average' : 200 , 'total' : 300 }
      ] ; 
  
      console.log( test ) ; 
  
      test.forEach( function( element , service_index , array ){
  
          array[ service_index ].count = 1111111 ;
          array[ service_index ].average = 2222222 ;
          array[ service_index ].total = 3333333 ;
  
      });
  
      console.log( test ) ;
  
      return ; 
  
  }
  </code></pre>
  
  <p>Here is a jsfiddle of the code <a href="http://jsfiddle.net/d46wh2cv/7/" rel="nofollow">http://jsfiddle.net/d46wh2cv/7/</a> . </p>
  
  <p>I read the specs at : </p>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach</a> </p>
  
  <p>but I don't see any explanation for this counter intuitive behavior.</p>
  
  <p>I am running Debian Linux with Google chrome 39.0.2171.95 and have also had the same result in Iceweasel 24.5.0. </p>
  
  <p>Thanks for the help. </p>