Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 window.localStorage.getItemItem get keys that start with

How could I use

window.localStorage.getItem();

to specify items in localstarage that start with the string 'QQ'. In my case the key can be: QQ + 3 digits, so I just need to specify that it starts with the string 'QQ'...?

like image 805
Nate Pet Avatar asked Mar 22 '12 20:03

Nate Pet


1 Answers

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.

like image 127
robertc Avatar answered Sep 29 '22 08:09

robertc