문제

Is it possible to edit a JSON object stored on web local storage? Currently I have a stringified JSON object

{fname":"Jerry","lname":"Lewis","email":"Jlewis@hollywood.com","password":"*********"}

using the function

localStorage.setItem() to save.

How can I make changes to the above ? Thanks

도움이 되었습니까?

해결책

You can do:

var myObj = JSON.parse(localStorage.getItem("yourKey"));
myObj.fname = "Clyde"; //change fname to Clyde
localStorage.setItem("yourKey", JSON.stringify(myObj));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top