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
  • 214,658
  • 40
  • 293
  • 332
Matthew
  • 348
  • 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 is supporting Monica
  • 142,542
  • 55
  • 282
  • 355