title: Javascript Global Variable Scope/Overwriting on Splice
body: <p>I have an issue I cant get to the bottom of, so any help would be much appreciated.</p>
  
  <ul>
  <li>A the top of my scipt I declare a global value ('<code>_raw</code>')</li>
  <li>(Using jQuery) I make an Ajax call, which returns JSON array data (I have
  checked, the JSON data is correct)</li>
  <li>I take this JSON response and assign it to <code>_raw</code></li>
  <li>When I click a link, <code>_raw</code> gets passed to a function, e.g. <code>function myFunction(dataArray)</code>, called with <code>myFunction(_raw)</code></li>
  <li>Within this function, based on some
  criteria, <code>dataArray</code> is spliced (i.e. <code>dataArray.splice(2,1)</code>)</li>
  <li><code>dataArray</code> is then returned.</li>
  </ul>
  
  <p>e.g.</p>
  
  <pre><code>var _raw;
  
  // AJAX call sets RAW to an array e.g. Apple, Banana, Pear, Pineapple, Coconut, Raspberry
  
  myFunction(dataArray){
    var data=dataArray;
    data.splice(2, 1);
    return data[0];
  }
  
  
  $('a').click(function(){
  
    result = myFunction(_raw);
    alert(result);
  // First time this is run, returns 'Pear', however, second time, returns 'Coconut'- as if the splice is being performed on _raw as well as myArray/data...
  
  });
  </code></pre>
  
  <ul>
  <li>I appreciate there is some poor code above, this is more to illustrate the issue</li>
  </ul>
  
  <p>The problem I have, is that as far as I can see, the only time <code>_raw</code> is set, is during the AJAX call, however, when the function myFunction is called, passing <code>_raw</code>, the splice also seems to effect <code>_raw</code> itself. Why is this happening?</p>