I am trying to update a property in localstorage. I don't want to loop through and reset the whole thing. Is this possible?
var aR = [
{ "id": 1, "width": 500 },
{ "id": 2, "width": 400 }
]
localStorage.setItem('test', JSON.stringify(aR));
// need to update property
localStorage['test'][1]['width'] = '720';
You can do the opposite of stringify, JSON.parse()
var arrayString = localStorage.getItem('test');
var a = JSON.parse(arrayString);
a[1]['width'] = '720';
// and do the same thing, stringify and store it back to local storage
Hope this helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With