html5 window.localStorage.getItemItem get keys that start with

前端 未结 4 1311
天命终不由人
天命终不由人 2021-01-14 01:22

How could I use

window.localStorage.getItem();

to specify items in localstarage that start with the string \'QQ\'. In my case the key

4条回答
  •  情书的邮戳
    2021-01-14 02:04

    Came across this and here is a solution in es6 :

    let search = 'QQ';
    let values = Object.keys(localStorage)
                       .filter( (key)=> key.startsWith(search) )
                       .map( (key)=> localStorage[key] );
    

提交回复
热议问题