I am running an old version of Angular - I have an object within my localStorage and I am trying to retrieve a single item from the object (rather than the whole the thing..)
var email = localStorage.user;
However the output of the localStorage.user variable is much longer (see below)- how would I retrieve the email address in this case '[email protected]'?
{"firstname":"Bob","lastname":"Dole","id":"2000001999","accountId":"15","email":"[email protected]","instances":[{"name":"Test"}]}"
LocalStorage values are always stored as
strings
. In order to refer to theemail
in the object, we need to convert it to a JSON. We can do that by parsing the string using JSON.parse() method like below :