Jump to content

how to compare items in two associate arrays?


cougar23

Recommended Posts

In and calendar/scheduling UI, I have two JS arrays (originalTimeSlots & currentTimeSlots) that store boolean values on if the checkbox for that time slot is selected or not.  They are both associative arrays with the index/key being in the format "DATE;APPT_START_TIME;APPT_END_TIME", i.e. originalTimeSlots["2008-11-17;08:00:00;09:00:00"] = true;  The original array holds the values of the checkboxes on load of page, while current holds the values after the user has (potentially) made changes by selected one or more slots and clicks a button to submit.

 

What I want to do is loop through both arrays comparing the values of the matching pairs and set a variable once one is found to be different. I tried two FOR loops but the length is coming out as zero(0).  How can I do what i'm trying to do?

 

var nothingChanged = false;

for(var i = 0; i < originalTimeSlots.length; i++) {
     for(var j = 0; j < currentTimeSlots.length; j++) {
          if(originalTimeSlots[i] != currentTimeSlots[j]) {
              nothingChanged = true;
              return;
          }
      }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.