Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  141] [ 2]  / answers: 1 / hits: 27119  / 12 Years ago, thu, october 18, 2012, 12:00:00

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


More From » html

 Answers
6

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



sessionStorage.getItem('key')
sessionStorage.setItem('key','value')


or store values permanently using



localStorage.getItem('key')
localStorage.setItem('key','value')


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



  localStorage.key(i);


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];
if(value.equals(desired_value))
console.log(key + => + value);
}

[#82498] Tuesday, October 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devane

Total Points: 451
Total Questions: 88
Total Answers: 100

Location: India
Member since Wed, Aug 26, 2020
4 Years ago
;