title: Alter and Assign Object Without Side Effects
body: <p>I currently have the following code:</p>
  
  <pre><code>var myArray = [];
  var myElement = {
    id: 0,
    value: 0
  }
  
  myElement.id = 0;
  myElement.value = 1;
  myArray[0] = myElement;
  
  myElement.id = 2;
  myElement.value = 3;
  myArray[1] = myElement;
  </code></pre>
  
  <p>The problem is that when I change the value of <code>id</code> and <code>value</code> for my second element, the values also change in the first element. Is there a way that I can keep adding new elements without it changing the value of the previously inserted values in the array?</p>