Problem getting user data on location ApplicationStorage

0

I would like to implement a menu "my account" in my project, this menu should show user data such as name, email etc, I am using jwt and the logged user data can be obtained in LocalStorage in this format: {"id":"598a8bc8b9dd44250819a7c4","name":"bruno","username":"kinge880","email":"[email protected]"} I would like to know how to access this array and get the name inside it I am using nodejs, angular 4 and mongodb

    
asked by anonymous 12.08.2017 / 23:06

1 answer

0

The function localStorage#getItem returns a String , so it is necessary to convert to an object using JSON#parse :

var user = JSON.parse(localStorage.getItem('user'));
var name = user.name;

console.log(name);
    
13.08.2017 / 04:06