html5 window.localStorage.getItemItem get keys that start with

前端 未结 4 1256
天命终不由人
天命终不由人 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:05

    You don't, get all the items and check them individually (code not tested):

    var results = [];
    for (i = 0; i < window.localStorage.length; i++) {
        key = window.localStorage.key(i);
        if (key.slice(0,2) === "QQ") {
            results.push(JSON.parse(window.localStorage.getItem(key)));
        }
    }
    

    If you want to do queries use something like IndexedDB.

提交回复
热议问题