vendredi 13 février 2015

Pushing to Array Overwrites Similar Entries


Basically what I am trying to do is grab an object from one array, append a property to that object, and then push that new object to a new array. The problem is once I push that object to the new array (with the new, different property), it overwrites all previous objects in the new array that have similar properties to this new object, despite me altering the property before pushing.


What should be:



{propA: "Name", propB: "Age", propC: "Location1"}
{propA: "Name", propB: "Age", propC: "Location2"}
{propA: "Name", propB: "Age", propC: "Location3"}


Becomes:



{propA: "Name", propB: "Age", propC: "Location3"}
{propA: "Name", propB: "Age", propC: "Location3"}
{propA: "Name", propB: "Age", propC: "Location3"}


Here you can find the code, with the relevant lines highlighted in yellow: http://ift.tt/1A4WA0s


And here is the console output to show that the correct information is being pushed to cliAllow but are being overwritten: http://ift.tt/1MjYAIT


I am re-writing this code from my old code which was my first time writing in javascript so please excuse what may be incorrect programming methods elsewhere in the code.


Your help is greatly appreciated. I've been trying to debug this for almost a week and I am heavily exhausted.





Aucun commentaire:

Enregistrer un commentaire