I have a JSON array and I want to compare its values with a String. For Example, My JSON Array is
{
"slot": ["10:00 AM", "10:30 AM", "03:30 PM"]
}
Now I am trying to access it in this way:
for (i in data.slot) {
console.log(slot[i] === "10:00 AM"); //this return false
if (slot[i] === "10:00 AM") btn1.disabled = true;
if (slot[i] === "10:30 AM") btn2.disabled = true;
if (slot[i] === "03:00 PM") btn3.disabled = true;
if (slot[i] === "03:30 PM") btn4.disabled = true;
}
Now whenever I am trying to compare it, the if statement returns false and the button doesn't get disabled. I got to know this on the Chrome Dev console. Any Suggestions would be appreciated.
else ifsince the comparisons are mututally exclusive, but it shouldn't make a difference.truefori == 0, andfalsefor all other iterations.let data = {...}