With all that being said lets Dive in.
While in the brainstorming process of creating my HTML5 Dart Tracking app I found myself with a problem of keeping the scores of the players even if your phone suddenly goes offline. Cookies were one way of keeping my data consistent but with HTML 5 there is an even better solution and that is localStorage. However while working with localStorage I found it had one unique quirk that required a bit of a workaround. That is localStorage can only hold strings. This was just not going to work because next to all my information that needed to be tracked was in the form of Arrays.
So after some research I found two functions that allow for arrays to be properly stored in localStorage. Below is some example code to help demonstrate the process.
The first function you will use will be
JSON.stringify(YourArrayVariable). This will convert your array into a string that localStorage can handle and later be parsed.
This leads me to the second function which retrieves your variable
ArrayVariable = JSON.parse(localStorage[‘NameOfArrayString’]). And there you have it now you can store arrays in localStorage.
If you have any questions, leave a comment below or email me at email@example.com