0
I have the following JSON, and within my code I have a check to see if autoLogin is enabled.
Object {autoLogin: "true",
autoLoginKey: "bWF4LnJvZ2VyaW8=&YWU4NjIwMGJhMTU0NWQzMjQ0ZmRlM2FhYWNiYTJjZmM="}
However to make this use check the value of autoLogin
, but I have to check it as string.
if(key.autoLogin === 'true'){//...code}
How do I stop instead of comparing as string, compare as Boolean same.
Type:
if(key.autoLogin === true){//code...}
You can try to convert the value to
boolean
but it is excessive and loses performance for what it is trying to do. For in json come just likeboolean
has to be placed without the"
on the server side and theparse
automatically puts the right kind:Object {autoLogin: true
– Isac
Yes, but Seto this value in localStorage:
localStorage.setItem('autoLogin', true);
, what is the best way to do?– Max Rogério
In localStorage the value is saved as
string
so it’s best to compare howstring
even– Isac
um.... did not know this detail... If you want to answer I mark as valid.
– Max Rogério