0

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.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Matthew
  • 358
  • 1
  • 3
  • 10
  • 1
    See 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 Answers1

0
function isSet(varName) {
    return localStorage.getItem(varName) === null
}

isSet('foo');
gdoron
  • 147,333
  • 58
  • 291
  • 367