title: Performance of modifying an array in an object: to use a variable, or not?
body: <p>Consider the following JavaScript global object:</p>
  
  <pre><code>var obj = { key1: [ 'data1', 'data2', ... ], key2: [ 'data1, 'data2', ... ], ... }
  </code></pre>
  
  <p>Assume I have a function that needs to modify the array assigned to a specific key in <code>obj</code>. Is it more efficient to use a local variable for my computations and modify the array at the end of my function, or should I be modifying the array directly, since it's not deep within the object?</p>
  
  <p>In essence, I am asking which function is more efficient:</p>
  
  <pre><code>function local_variable() {
      var foo = [];
      $( selector ).map(function() {
          foo.push( $( this ).val() );
      });
      obj[ keyx ] = foo;
  }
  </code></pre>
  
  <p>versus</p>
  
  <pre><code>function global_object() {
      obj[ keyx ] = [];
      $( selector ).map(function() {
          obj[ keyx ].push( $( this ).val() );
      });
  }
  </code></pre>
  
  <p>As always, if there is an even better way to do what these functions do, please enlighten me.</p>