QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Home
  • QIdea
  • QTrack
Home Carbon Ads How to Store Arrays in HTML5 localStorage

How to Store Arrays in HTML5 localStorage

HTML5 localStorage lets you store key/value pairs of data. Both key and value needs to be a string.

To store arrays as a key or value you need to encode the array into a JSON string. And while retrieving you need to decode it back to an array.

Here is example code

var array = [1, 2, 3];

localStorage.setItem("array", JSON.stringify(array));
array = JSON.parse(localStorage.getItem("array"));


console.log(typeof array); //object
console.log(array); //[1, 2, 3]
Mar 12, 2015Narayan Prusty
How to Store Objects in HTML5 localStorageWordPress MySQL Database Table Structures
Comments: 1
  1. Tessa
    6 years ago

    Fantastic! Great!. … Fantastic! Great!. Maolrlveus! Unique! By the way of music I want to show you what musicians of Brazil and Argentina are doing in folklore music with a accordion. If you want, please search for these 4 videos, really interesting and special and awesome:- Voninho e Marcelo- Tio Mederico- Dvd Os Serranos 40 anos- Sempre Gaúchos- Faz que vai mas não vai – Adelar Bertussi- CHANGO SPASIUK EN FORMOSA KILOMETRO 11 -10/10/2009 (4)

    ReplyCancel

Leave a Reply to Tessa Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Narayan Prusty

I am a software engineer specialising in Blockchain, DevOps and Go/JavaScript. This is my personal blog where I write about things that I learn and feel interesting to share.

8 years ago 1 Comment Web Development
Share this
0
GooglePlus
0
Facebook
0
Twitter
0
Linkedin
Related Articles
  • How to Store Objects in HTML5 localStorage
  • Storing Meta Data In HTML Tags Using data-* Attributes
  • WordPress $notoptions Array
  • Storing Key Value Pairs in CSV using PHP
  • JavaScript “…” Operator
Our Sponsor
My Books

2014 - 2015 © QNimate
All tutorials MIT license