Results 1 to 11 of 11

Thread: [RESOLVED] Storing array/object into localStorage?

Threaded View

  1. #1

    Thread Starter
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Resolved [RESOLVED] Storing array/object into localStorage?

    localStorage will only store values in string format. Is there any way to modify it to store arrays/objects? http://hacks.mozilla.org/2009/06/localstorage/ says it's possible to use native JSON support to create an object store on top of localStorage, but I can't work out how to apply the given example code:
    javascript Code:
    1. Storage.prototype.setObject = function(key, value) {
    2.     this.setItem(key, JSON.stringify(value));
    3. }
    4.  
    5. Storage.prototype.getObject = function(key) {
    6.     return JSON.parse(this.getItem(key));
    7. }

    Can anyone help me decipher this and show me how to use it to store objects in localStorage?
    Last edited by tr333; Jan 27th, 2010 at 12:36 AM.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width