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))
Edit
as Ghommey has mentioned, I've used the 2nd option to check that value. Even if the parions statement returns false
, it also gets inside the code. See the pic below
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))
Edit
as Ghommey has mentioned, I've used the 2nd option to check that value. Even if the parions statement returns false
, it also gets inside the code. See the pic below
- 2 Please post the JSON response you get. – Bojangles Commented Aug 17, 2012 at 8:53
-
What is
typeof file.showInTable
? – xdazz Commented Aug 17, 2012 at 8:53 -
Is it set to the boolean value
false
or the string'false'
? – Anthony Grist Commented Aug 17, 2012 at 8:54 - 1 Duplicate of stackoverflow./questions/263965/… – Sergii Stotskyi Commented Aug 17, 2012 at 8:54
- Anthony Grist: it is set to false or true (as bool) – Tony Commented Aug 17, 2012 at 8:58
2 Answers
Reset to default 2it is set to false or true (as bool) - Tony
Why do you pare a boolean as a string?
Just pare it as a boolean:
if(file.showInTable === true) {
}
or
if(file.showInTable !== false) {
}
This is ugly, but why not?
if (file.showInTable === "false") file.showInTable = false;