javascript - saving specific data from localstorage -


i've been workinig on project uses angularjs , have been using localstorage storing data. i'm facing difficulties in separating specific data localstorage before clear it.

following sample data stored in localstorage.

localstorage.setitem("favclub_"+userid,json.stringify($scope.favclub)); localstorage.setitem("cityofbirth_"+userid,json.stringify($scope.cityofbirth)); 

all keys stored have userid appended unique.

example:

userid: john key: favclub_john & cityofbirth_john 

now need keep data favclub , cityofbirth of users before clear storage on log in.

i thinking of having array store required data , iterate through local storage , keep data matches requirements. wondering how can loop through localstorage such dynamically varying keys.

sorry if questions been asked. tried searching couldn't find similar question. input great.

thanks in advance!

as far know, can't iterate on localstorage keys. use different approaches, example:

localstorage.setitem("myappdata", json.stringify(['john': {'cityofbirth': 'granada', 'favclub': 'c.b. granada'}])); 

so able myappdata , iterate on it.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -