In a loop, all array elements get value of the last one
<p>I have the following:</p>

<pre><code>var travel_path=[];
var point={
    "left": 0,
    "top": 0
};
while(/*some condition here*/){
    point.left+=3;
    point.top+=5;
    travel_path.push(point);
}
console.log(travel_path);
</code></pre>

<p>Now, if the <code>while</code> loop runs for 10 iterations, instead of getting the incremented values of <code>left</code> and <code>top</code> in each element, I get 10 elements with the same value of <code>{"left": 30, "top": 50}</code>.</p>

<p>So it seems that, even though I'm using push to append elements to the end of the array, it's somehow updating all the previous elements as well.</p>

<p>Any ideas how I can resolve this?</p>