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

**URL:** <https://forum.kirupa.com/t/why-am-i-an-idiot-assigning-array-values/227021>\
**Category:** flash\
**Created:** [May 26, 2007, 12:08am UTC](https://forum.kirupa.com/t/why-am-i-an-idiot-assigning-array-values/227021 "2007-05-26T00:08:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickcherryjiggz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nickcherryjiggz/32/2107_2.png) [@nickcherryjiggz](https://forum.kirupa.com/u/nickcherryjiggz)\
**Post date:** [May 26, 2007, 12:08am UTC](https://forum.kirupa.com/t/why-am-i-an-idiot-assigning-array-values/227021/1 "2007-05-26T00:08:20Z")

</div>

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?

```auto
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:

```auto
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

```
