HTML5 Localstorage & jQuery: Delete localstorage keys starting with a certain word

前端 未结 2 820
春和景丽
春和景丽 2020-12-25 13:23

I have 2 apps working together with localstorage and I was wondering how can I delete all the keys which start with note- and todo- . I know localstorage.clear() clears ever

2条回答
  •  Happy的楠姐
    2020-12-25 14:02

    Object.keys(localStorage)
          .forEach(function(key){
               if (/^todo-|^note-/.test(key)) {
                   localStorage.removeItem(key);
               }
           });
    

提交回复
热议问题