我已经尝试了下面的代码来删除最后添加的数组(用户数组)对象。它在console中工作。但它不会从localstorage中删除数据。任何帮助都将不胜感激
var delRecord = JSON.parse(localStorage.getItem("MyRecords"));
for (var d = 0; d < delRecord .length; d++) {
delRecord [d].Users.pop();
}
pop()方法会起作用还是有任何建议?
答案 0 :(得分:0)
您需要将结果写回本地存储:
var delRecord = JSON.parse(localStorage.getItem("MyRecords"));
for (var d = 0; d < delRecord .length; d++) {
delRecord[d].Users.pop();
}
localStorage.setItem("MyRecords", JSON.stringify(delRecord));