cougar23 Posted October 15, 2008 Share Posted October 15, 2008 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 https://forums.phpfreaks.com/topic/128470-how-to-compare-items-in-two-associate-arrays/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.