# Why am I an idiot? (Assigning array values...)

I’m stumped, guys. I have a class called calDay, whose parameters are a number and an array. The function below is rather in depth, so unless someone would like me to explain it, I won’t bother because I don’t think it’s too relevant to the issue. But what’s happening is this: Each time the outer for loop (d) makes its increment, a new element is added to calDayArray, this new element being an object of the class calDay. As you can see by the traced output below, each time a run through the loop has been made, the values assigned to this new object are unique. The next time through the loop, however, all values of previous objects in the array are set to be the same as the values of the most recent object in the array. By the end of the loop, every calDay object in the calDayArray array has the same values as the last object created. Say that 10 times fast.

Could someone tell me the stupid thing I’m doing to screw this up?

``````for (d = 0; d < Number(calendarDaysInMonth) + Number(calendarDaysInNextMonth); d++){
a = 2;
for (rt = 0; rt < roomTypeArray.length; rt++){
ra[rt] = raa[rt][d];
if (a < ra[rt]){
a = ra[rt];
}
}
calDayArray[d + 1] = new calDay(a, ra);

trace("calDayArray " + String(d + 1) + ", " + String(d) + ", " + String(d - 1));
for (c = 0; c < roomTypeArray.length; c++){
trace("     " + calDayArray[d + 1].roomAvailability[c] + ", " + calDayArray[d].roomAvailability[c] + ", " + calDayArray[d - 1].roomAvailability[c]);
}
trace("");
}
``````

Section of traced output:

``````calDayArray 1, 0, -1
2, undefined, undefined
0, undefined, undefined
0, undefined, undefined
0, undefined, undefined
0, undefined, undefined
2, undefined, undefined
calDayArray 2, 1, 0
0, 0, undefined
2, 2, undefined
2, 2, undefined
2, 2, undefined
2, 2, undefined
2, 2, undefined
calDayArray 3, 2, 1
2, 2, 2
0, 0, 0
0, 0, 0
0, 0, 0
2, 2, 2
0, 0, 0
calDayArray 4, 3, 2
0, 0, 0
2, 2, 2
2, 2, 2
2, 2, 2
0, 0, 0
2, 2, 2
calDayArray 5, 4, 3
2, 2, 2
0, 0, 0
0, 0, 0
1, 1, 1
2, 2, 2
0, 0, 0
``````