Reputation: 12695
in the response from my server I get a JSON object. It has a boolean flag.
if(file.showInTable == 'true') {
}
But, even if showInTable
is set to false
, I get inside that code block. How to cope with that ?
I tried:
if(file.showInTable == 'true')
if(file.showInTable)
if(Boolean(file.showInTable))
as Ghommey has mentioned, I've used the 2nd option to check that value. Even if the comparions statement returns false
, it also gets inside the code. See the pic below
Upvotes: 3
Views: 7295
Reputation: 8845
This is ugly, but why not?
if (file.showInTable === "false") file.showInTable = false;
Upvotes: 1
Reputation: 38142
it is set to false or true (as bool) - Tony
Why do you compare a boolean as a string?
Just compare it as a boolean:
if(file.showInTable === true) {
}
or
if(file.showInTable !== false) {
}
Upvotes: 2