Вопрос

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