How do I get an object's value stored in localStorage?

前端 未结 1 1352
被撕碎了的回忆
被撕碎了的回忆 2021-01-26 23:20

I have stored an object with multiple properties in localStorage. It does not contain a single value like a string or a number. The name of the localStorage key is UserDat

1条回答
  •  温柔的废话
    2021-01-27 00:19

    Use JSON.parse like

    var userData= JSON.parse(localStorage.getItem('UserData'))
    this.operatorDni=userData.operatorDni;
    

    Also save it like

    localStorage.setItem('UserData',JSON.stringify(yourObject))
    

    0 讨论(0)
提交回复
热议问题