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
booleanbut it is excessive and loses performance for what it is trying to do. For in json come just likebooleanhas to be placed without the"on the server side and theparseautomatically 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
stringso it’s best to compare howstringeven– Isac
um.... did not know this detail... If you want to answer I mark as valid.
– Max Rogério