javascript array objects

javascript

Solution

Because you are storing a reference to `transitionInitial`, not a copy of it. `transitionInitial` points to an object in memory, and you are storing a reference to this object in `transitions[k]`. Regardless of the iteration you are at, you are always changing the same object.

Problem

http://jsfiddle.net/gfuKS/5/ ``` var transitionInitial = {property: "none"}; var rules = ["color", "background-color"]; var transitions = []; for ( var k = 0; k < rules.length; k++) { transitions[k] = transitionInitial; transitions[k].property = rules[k]; alert(transitions[0].property); }​ ``` Why at the second iteration transitions[0].property equals "background-color"?

Original source