AnsweredAssumed Answered

Working with an array of objects

Question asked by srowsell on Jan 28, 2014
Latest reply on Jan 29, 2014 by srowsell
This is just about the stupidest problem I've seen but can't solve, but here is the code snippet:


var items;
var dailyReports=new Object();
var dailyReportsArray=new Array();

if (goodDoc)
{
   var j=0;
   items=reportList.getChildren();
   for each (child in items)
   {
      if (child.properties["reportdl:frequency"]=="Daily")
      {
         
         dailyReports.uniqueIdentifier=child.properties["reportdl:uniqueIdentifier"];
         dailyReports.suffix=child.properties["reportdl:suffix"];
         dailyReports.department=child.properties["reportdl:department"];
         dailyReports.found=false;
         dailyReportsArray.push(dailyReports);
         blurb+=j+" "+dailyReportsArray[j].uniqueIdentifier+" "+dailyReportsArray[j].suffix+" "+dailyReportsArray[j].department+" "+dailyReportsArray[j].found+"\n";  //comparison 1
         j++;
      }
      //blurb+=dailyReports.uniqueIdentifier+" "+dailyReports.suffix+" "+dailyReports.department+" "+dailyReports.found+"\n";
   }
   
   for (var i=0;i<dailyReportsArray.length;i++)
   {
      blurb+=i+" "+dailyReportsArray.uniqueIdentifier+" "+dailyReportsArray.suffix+" "+dailyReportsArray.department+" "+dailyReportsArray.found+"\n"; //comparison 2
   }


It doesn't matter where these values come from; trust me that they are being populated.  (In fact I'm grabbing them from a site data list, but that's really not important, since that's working just fine.)

Look at the assignment statement tagged "comparison 1".  As you can see, I'm assigning an int, and then each of the four properties of the new array, one at a time.  (These lines are there for debugging purposes.)  Now look at the assignment statement tagged "comparison 2".  In my mind it should look *exactly* like the first statement.  Unfortunately this isn't true; instead I get the last property values repeated for each iteration of the second loop.  For the first "blurb" I get values like this:

0 Cards v16 CDC false
1 Houses v9 Hamilton false

For the second "blurb" I get values like this:

0 Activity r22 Messages false
1 Activity r22 Messages false
2 Activity r22 Messages false

(This is repeating the last value of the array.)

Were I not already bald, I would have pulled out my hair by now.

Anyone have any thoughts?

Steve

Outcomes