title: Javascript object deletion deleting clones
body: <p>I have an object in JavaScript that looks like this:</p>
  
  <pre><code>var obj = {
    key: [1],
    key2: [2],
    key3: [3]
  };
  </code></pre>
  
  <p>And I eventually end up copying one of these elements into the object under a different key:</p>
  
  <pre><code>obj.key4 = obj.key.slice ()
  </code></pre>
  
  <p>Which should create a copy of key &amp; place it into key4. This works - after this point, the new key4 is added into the object.</p>
  
  <p>However, I'm then removing the original array (under key):</p>
  
  <pre><code>delete obj.key;
  </code></pre>
  
  <p>And it seems that once the garbage collector runs, the values under key4 are also deleted. I've tried referencing obj.key without slicing, and that produces the same issue.</p>
  
  <p>It seems that the only fix I've been able to make is to not delete obj.key, but this produces errors with my code later.
  I've instead tried this as well, in place of the deletion:</p>
  
  <pre><code>obj.key = null;
  </code></pre>
  
  <p>But this also results in the same problem - key4 will be deleted from the object. I've tried rewriting my code &amp; restructuring the object, but I run into the same issues. Is there something I'm missing here?</p>