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;
          }
      }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.