How do you clone an Array of Objects in Javascript
<p>...where each object also have references to other objects within the same array?
When I first came up with this problem I just though of something like </p>

<pre><code>var clonedNodesArray = nodesArray.clone()
</code></pre>

<p>would exists and searched for info on how cloning objects in javascript. I did find a <a href="http://stackoverflow.com/questions/122102/what-is-the-most-efficent-way-to-clone-a-javascript-object">question</a> on StackOverflow 
(answered by the very same John Resig) and he pointed out that with jQuery you could do</p>

<pre><code>var clonedNodesArray = jQuery.extend({}, nodesArray);
</code></pre>

<p>to clone an object. I tried this though, this only copies the references of the objects in the array. So if I </p>

<pre><code>nodesArray[0].value = "red"
clonedNodesArray[0].value = "green"
</code></pre>

<p>the value of both nodesArray[0] and clonedNodesArray[0] will turn out to be "green". Then I tried</p>

<pre><code>var clonedNodesArray = jQuery.extend(true, {}, nodesArray);
</code></pre>

<p>which deep copies an Object, but I got "<em>too much recursion</em>" and "<em>control stack overflow</em>" messages from both Firebug and Opera Dragonfly respectively.</p>

<p>How would you do it? Is this something that shouldn't even be done? Is there a reusable way of doing this in javascript?</p>
