D.J. D.J. - 3 years ago 239
Javascript Question

HTML5 localStorage getting key from value

localStorage.getItem will retrive value.

and setItem will set value.

But If I want to know which key was associated with this particular value? Then how to get Key of that.?

so question I have reffered

Answer Source

visit Html5 Storage Doc to get more details. Use the following syntax to set and get the values in localstorage/sessionstorage for storing values for a session


or store values permanently using


and u said u want to know the value but you want key then you can use the function


or also you can loop through the available keys and get the desired key by cross checking the value

for(var i=0, len=localStorage.length; i<len; i++) {
    var key = localStorage.key(i);
    var value = localStorage[key];
    console.log(key + " => " + value);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download