My array
var obj = [{"2021-07-30":"8:00 AM - 10:00 AM"},{"2021-07-30":"12:00 PM - 2:00 PM"}];
How can I return true if the key and value pair match? Here there is a duplicate "date" because of that I am not able to get the code correctly?
My code
var date = "2021-07-30";
var time = "12:00 PM - 2:00 PM";
if ( date in obj[0] && obj[0][date] == time) {
console.log('exists');
console.log(obj[0][date]);
} else {
console.log('does not exist');
}
Above code returns "does not exist", even though that key and value pair exist.