LocalStorage and JSON


Hi there,

    var data = {
    "username": $scope.loginData.username,
    "password": $scope.loginData.password
$http.post("http://url/to/login.php", data,{"username": $scope.loginData.username,"password": $scope.loginData.password})
       localStorage.setItem("LoggedOnProfile", JSON.stringify(data));
       console.log(localStorage.getItem("LoggedOnProfile")); //returns [{id:..., firstname:...,}]
       var LoggedOnProfile = JSON.parse(localStorage.getItem("LoggedOnProfile"));
       console.log(LoggedOnProfile.firstname); //returns undefined

Why does the console.log return ‘undefined’? Everthing works, including logging the .getItem…

Thanks in advance,



Where “firstname” is defined?


It looks allright. I tried it on console it works.Look at this fiddle.


Thanks for helping!

It works now, didn’t change anything in my code… I’m only at a different location (work/home). Maybe it has to do something with that?

Thanks again.