【发布时间】:2023-03-10 08:34:02
【问题描述】:
我一直在开发一种工具来帮助人们在 GTA 中跟踪他们的汽车,但我不知道如何删除它们。
我尝试了多种方法,但无法正常工作。
这是我的密码笔https://codepen.io/Tristangre97/pen/dyoyOKw?editors=1010
function deleteItem(index) {
var existingEntries = JSON.parse(localStorage.getItem("allCars"));
existingEntries.splice(0, index); // delete item at index
}
【问题讨论】:
-
请提供minimal reproducible example。一个 codepen 的链接是不够的。
-
从数组中删除项目后,您应该再次调用
localstorage.setItem以更新本地存储
标签: javascript arrays local-storage