[英]delete specific element in an array of local storage
您可以獲取要刪除的項目索引,然后只需使用splice
從數組中刪除該項目並在 localStorage 中再次設置您的datas
。
演示代碼:
var to_delete = "WLP003" //var datas = localStorage.getItem('datas');//parse it //suppose this is data var datas = ["WLP001", "WLP002", "WLP003", "WLP004", "WLP022"]; var index = datas.indexOf(to_delete);//get index datas.splice(index, 1);//remove it console.log(datas) localStorage.setItem('datas', JSON.stringify(datas));//set again
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.