I need to access to some props within an object, but I am getting an object as a string, this object comes from LocalStorage, what should I do to access to that props in that object ?
lobby: "[object Object]"
there is the object
I need to access to some props within an object, but I am getting an object as a string, this object comes from LocalStorage, what should I do to access to that props in that object ?
lobby: "[object Object]"
there is the object
localStorage
stores strings. If you try to save an object, it will first call toString()
, resulting in "[object Object]"
.
You're better off saving it as JSON:
localStorage.setItem( 'apogeLiveLobbyData', JSON.stringify(tokenData.lobbyData));
and retrieving it that way, too
lobby : JSON.parse( localStorage.getItem('apogeLiveLobbyData') )
You can not store an object into local storage since it holds strings. So you need to make it a string to store and than parse it to get it back to an object.
localStorage.setItem('apogeLiveLobbyData', JSON.stringify(tokenData.lobbyData));
var data = JSON.parse(localStorage.getItem('apogeLiveLobbyData'));