javascript - Check local storage variable already present, if not create a new one -


i want create local storage variable checking present or not. if variable exist change variable name , create new one. not understand how it. please me this. thanks

here code

var vcount=1; var vname='session_'+vcount; while(localstorage.getitem(vname) === null) {     vcount++;    vname='session_'+vcount;     //if variable name available create new variable  } 

start count name , query local storage see if exists. if - increment count , save value loan storage. if not - doesn't exist save original.

var vcount=1; var vname='session_'+vcount;  var storedname= sessionstorage.getitem("vname"); if (storedname){     var vcount += 1;     var vname='session_' + vcount;     localstorage.setitem(vname, vname);     //this increment number , set variable name } else {   localstorage.setitem("vname", vname); } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -