I have a list of objects, in each object I have a date and time.
onClick of a td element (its a calendar) I check the time on the calendar, then check if it matches any times in my list of objects.
onSelect: function(date) {
for (var i = 0; i < dateArray.length; i++) {
for (var prop in dateArray) {
if (date === dateArray[prop].date) {
console.log(dateArray[prop].time);
}
}
}
}
So I loop through my array, which is an array of objects. To be able to get anything out I need to do a for in loop, and in there I do a condional statement to say if the dates match. The console.log out the corect time.
However, the time gets console logged out 10 times since it's in a loop. But the only way I could get inside my object array was to loop through them.
How should I actually be doing this.
EDIT
dateArray structure: list of objects like [ object, object, object, object ] and once I loop through them, within each object it looks like :
Object {title: "The Title", date: "01/01/2017", time: "07:30pm", available: true,}
for (var prop in dateArray)actually give you an index number to use indateArray[prop]? shouldn't you be usingi?