title: Javascript passing arrays to functions by value, leaving original array unaltered
body: <p>I've read many answers here relating to 'by value' and 'by reference' passing for sending arrays to javascript functions. I am however having a problem sending an array to a function and leaving the original array unaltered. This example llustrates the problem:</p>
  
  <pre><code>function myFunction(someArray)
  {
  // any function that makes an array based on a passed array;
  // someArray has two dimensions;
  // I've tried copying the passed array to a new array like this (I've also used 'someArray' directly in the code);
  
  funcArray = new Array();
  funcArray = someArray;
  
  var i = 0;
  
      for(i=0; i&lt;funcArray.length; i++)
      {
      funcArray[i].reverse;
      }
  
  return funcArray;
  
  }
  </code></pre>
  
  <p>I can't understand why anything in this function should alter the original array.</p>
  
  <p>calling this function directly changes the original array if the function call is assigned to a new array:</p>
  
  <pre><code>myArray = [["A","B","C"],["D","E","F"],["G","H","I"]];
  anotherArray = new Array();
  
  anotherArray = myFunction(myArray);
  // myArray gets modified!;
  </code></pre>
  
  <p>I tried using .valueOf() to send the primitive:</p>
  
  <pre><code>anotherArray = myFunction(myArray.valueOf());
  // myArray gets modified!;
  </code></pre>
  
  <p>I have even tried breaking the array down element by element and sub-element by sub-element and assigning all to a new 2-d array and the original array still gets modified.</p>
  
  <p>I have also joined the sub-elements to a string, processed them, split them back into arrays and the original array still gets modified.</p>
  
  <p>Please, does any one know how I can pass the array values to a function and not have the passed array change?</p>