Sunday, January 28, 2018

How do you store an array in Local Storage?

My previous post showed how to store a single piece of information in Local Storage (Browser Storage). However instead of a single piece of data you want to store an array of items.
Let us say your array has three elements, rose, jasmine and hyacinth and you want to store in an array named 'flowers'.
The following page shows how you may store array and retrieve array elements using JavaScript. Each statement is commented (view image magnified, if necessary).


ArrayStoreLocalStorage.png

Place this page in IIS's wwwroot folder and browse. You can see the elements in the array in LocalStorage.


ArrayStoreLocalStorage1.png

You can see more clearly here in the Microsoft Edge's developer window. Data stored from the previous post is also seen.



ArrayStoreLocalStorage2.png

No comments: