Reputation: 586
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":"[email protected]","password":"*********"}
using the function
localStorage.setItem()
to save.
How can I make changes to the above ? Thanks
Upvotes: 1
Views: 1082
Reputation: 104795
You can do:
var myObj = JSON.parse(localStorage.getItem("yourKey"));
myObj.fname = "Clyde"; //change fname to Clyde
localStorage.setItem("yourKey", JSON.stringify(myObj));
Upvotes: 5