I am creating a HTML5 web app, and it uses localStorage to store its data. I would like to know how to see if a variable is set in localStorage, but I would like to have it so that the user inputs the name of the variable to retrieve.
Asked
Active
Viewed 432 times
0
-
1See this question: http://stackoverflow.com/questions/3262605/html5-localstorage-check-if-item-isset – gen_Eric Mar 21 '12 at 18:54
-
And: [How to access object using dynamic key?](http://stackoverflow.com/questions/6921803/how-to-access-object-using-dynamic-key) – Felix Kling Mar 21 '12 at 18:56
1 Answers
0
function isSet(varName) {
return localStorage.getItem(varName) === null
}
isSet('foo');

gdoron
- 147,333
- 58
- 291
- 367