0

How to get the data from the localStorage I m having the data like that format localStorage

{"refresh":"",
"access":"",
"id":"dbf4d515-d71e-45d9-8d5c-5efce2b217c7",
"name":"",
"email":"",
"token":""}

Whenever I try to get the data like this

const data = localStorage.getItem("userData")
console.log(data.id) 

it shows undefined. Ihv seen multiple answers with this type of issue and tried but not able to get the data from localStorage. Anybody can highlight what I'm missing here.

atropa belladona
  • 474
  • 6
  • 25
  • 1
    Does this answer your question? [How to Store Objects in HTML5 localStorage?](https://stackoverflow.com/questions/2010892/how-to-store-objects-in-html5-localstorage) – lusc Feb 10 '22 at 18:35
  • 1
    The accepted answer does show how to get the value. – lusc Feb 10 '22 at 18:38
  • 4
    @atropabelladona why not? The answers explain that the returned value has to be parsed. Because the value type stored in local storage aus string. – t.niese Feb 10 '22 at 18:39

0 Answers0