Question

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

Était-ce utile?

La solution

You can do:

var myObj = JSON.parse(localStorage.getItem("yourKey"));
myObj.fname = "Clyde"; //change fname to Clyde
localStorage.setItem("yourKey", JSON.stringify(myObj));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top