Javascript save current contents of object in another object?
<p>Let's say I have:</p>

<pre><code>var obj1 = {
    '0': 'a',
    '1': 'b'
    }

var obj2 = obj; // I want to create a new object with obj contents

obj1[2] = 'c' // Now I modify obj without modifying obj2

obj1 = obj2; // so I can restore obj later
</code></pre>

<p>However modifying obj also modificates obj2. How can I create a copy of obj1 that is independent of it?</p>
