Reputation: 6669
I have a json array that contains an element that can be "ok" or "ko".
If I do console.log(data.esito)
I see that the value is "ok" or "ko" as expected.
So I tried to do:
console.log(data.esito);
if(data.esito == 'ok'){
console.log('code for ok');
//code if is ok
}else{
console.log('code for ko');
//code if is ko
}
But it never enter the if. Even if the result is "ko" or if the data.esito == 'ok' was faulty the code for ko is not executed.
What am I missing? Must be something obvious but cannot see what
Upvotes: 1
Views: 37
Reputation: 136104
if the value of your variable data.esito
has leading or trailing spaces the strict checking of the string ok
will evaluate false.
You could try using trim()
to remove any extra whitespace from the beginning or end of the variable.
Upvotes: 2