Changing the variables of a class in OOP in javascript
<p>I have defined a function called Node which stores the properties of nodes in a graph data structure. The function is something like this: </p>

<pre><code>function Node(){
    ...
    this.outEdges = [];
    this.inEdges = [];
    ...
}
</code></pre>

<p>where the inEdges and outEdges store elements of type Edge which is another function I have defined. During the program these arrays are filled with elements.</p>

<p>At some point in my code I need to reset these two arrays so I write:</p>

<pre><code>    nodes[i].outEdges.length = 0;
    nodes[i].inEdges.length = 0;
</code></pre>

<p>where nodes is an array of elements of type Node and I am accessing an element in a for loop.</p>

<p>The problem is, after setting outEdges and inEdges to 0, I expected them to be [] in the nodes[i] property list. However, when I output nodes[i] into console, the outEdges and inEdges still have the elements in them. The stranger thing is that when I output nodes[i].outEdges to console, it prints [] , which is correct, but clicking on [ ] again opens the list of the elements! I can't really figure out why the nodes[i] variables don't change?</p>
