I have a function that contains the following code:
stores = [];
console.log('in stores d.length is ', districts.length);
districts.forEach( function ( dis ) {
dis.store.forEach( function( store ) {
store.structure = dis.structure;
store.structure.dis = dis.district_nbr;
store.structure.sto = store.store_nbr;
//store.message = getMessage(store.structure);
console.log('store st is ', store.structure);
stores.push( store );
});
});
stores.forEach( function ( s ) {
console.log("after set Master this is stores ", s.structure);
})
As the loops go, I initialize an object structure
for each store starting out as the structure from the parent dis object which has a few fields and has been validated as correct. I then add an additional fields to the structure object to account for the district number and store number. Each dis object has a unique set of stores.
The console.log
in the nested for loops displays the correct structure for the store. However, when I print them after the fact, the stores all have the final district number in the loop and the final store number in the loop instead of their respective correct values.
QUESTION: Does something happen in Array.push() that I'm not aware of that through things out of whack? I think my real question is what am I missing?