数组中的本地存储更新 属性
localstorage update property in array
我正在尝试更新本地存储中的 属性。我不想遍历并重置整个事情。这可能吗?
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';
你可以做与字符串化相反的事情,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
希望对您有所帮助:)
我正在尝试更新本地存储中的 属性。我不想遍历并重置整个事情。这可能吗?
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';
你可以做与字符串化相反的事情,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
希望对您有所帮助:)