title: Array value changes if object value is changed
body: <p>The array changes its value even though it was pushed earlier</p>
  <pre><code>var original = 
  [{
      a: 1,
      data: 
          { b: 'before' }
  },
  {
      a: 2,       
      data: 
          { b: 'before' }
  }];
  
  var arr1 = [];
  var arr2 = [];
  
  
  for(i=0; i&lt;original.length; i++) {
      let value = original[i];
  
      //pushed earlier
      arr1.push(value);
  
      let newvalue = original[i];
      if (newvalue.data.b == &quot;before&quot;) {
          newvalue.data.b = &quot;after&quot;;
          arr2.push(newvalue);
      }
  }
  
  console.log(&quot;ARRAY 1 &quot;);
  console.log(arr1);
  console.log(&quot;ARRAY 2 &quot;);
  console.log(arr2);
  </code></pre>
  <p>produces</p>
  <pre><code>ARRAY 1 
  [ { a: 1, data: { b: 'after' } }, { a: 2, data: { b: 'after' } } ]
  ARRAY 2
  [ { a: 1, data: { b: 'after' } }, { a: 2, data: { b: 'after' } } ]
  </code></pre>
  <p>I am guessing this has something to do with how JS changes the value since it is being reference by the original array itself.</p>
  <p>Whats the optimal solution in such cases where you have to retain the original array while use it to modify and create another array?</p>