Why do you need this? In addition, localStorage
is an object that contains all key pairs: values stored in the browser. If you want to copy it, you must skip its properties.
However, it looks like what you want / need, it is a shell that will abstract from the localStorage
insterface, so if you change the way you store your data later, you will only need to change this shell without your code noticing any difference. I do it myself.
There are several libraries that achieve this with varying levels of complexity and / or functionality. For example, jStorage allows you to use userData
in IE if localStorage
not available. My Storage.js only wraps localStorage
, but has methods for working with multiple items at once.
source share