title: How to clone a Javascript Array of Objects?
body: <p>I have a result set which is an array of objects. I need to clone this so I can make changes to it, without touching the original data.</p>
  
  <pre><code>var data = w2ui.grid.records,
  exclude = Array('recid', 'w2ui'); // Exclude these data points from the pivot
  // Modify our tempData records to remove HTML
  $.each(data, function(key, value) {
      $.each(value, function(_key, _value) {
          if(jQuery.inArray(_key, exclude) != -1) {
              delete data[key][_key];
          }else{
              data[key][_key] = $('&lt;div&gt;'+_value+'&lt;/div&gt;').text(); // &lt;div&gt;&lt;/div&gt; for those which are simply strings.
          }
      });
  });
  </code></pre>
  
  <p>In this example, I created a variable called <code>data</code> and set it to my "Source Data". </p>
  
  <p>I expected to be able to make changes to this new data variable but it appears that when making changes to it, the source data is being changed (<code>w2ui.grid.records</code>).</p>
  
  <p>Is there a proper way to clone this set so I can have a new instance of the data to modify?</p>