I'm adding a value to each object in the object list. But I don't know why its adding the date for every object in every loop.
this is my code:
var emptyday: {
"date":""
}
//make list of days in month
var monthlist = [];
for (i=0;i<=days_in_months;i++) {
monthlist[i] = emptyday;
}
So in my example lets say that days_in_months is 31 (days)
Now comes the adding
for (x=1;x<=days_in_months;x++) {
console.log(x);
if (x<10) {
daynumber = "0" + x;
} else {
daynumber = x;
}
datestring = year + "-"+ (month+1) + "-" + daynumber;
dayofmonth = monthlist[x];
dayofmonth["date"] = datestring;
//monthlist[x].date = datestring;
}
When I try adding (dayofmonth["date"] = datestring or monthlist[x].date) it adds to all date values of all objects in every loop.
The console.log looks like this for the first loop:
[Object { date= "2013-1-01"}, Object { date= "2013-1-01"}, Object { date= "2013-1-01"}, Object { date= "2013-1-01"}, Object { date= "2013-1-01"}, Object { date= "2013-1-01"}, etc
for 31 times in the first loop
And in the last loop it will be 2013-1-31
I don't understand why it is adding that value to all objects. I have tried console.log and debugging all over the place to read out values and trying to understand what goes wrong, but still haven't found a solution