Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Ahh! localstorage!

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #161974
    Marteen
    Participant

    Hi guys,

    I’m working on a Js application that uses localstorage to remember a couple variables that alter the application when set. I’m using:

    localStorage.setItem('settings',JSON.stringify(this.settings));
    

    to store the information to localstorage, then:

    this.settings = JSON.parse( localStorage.getItem( 'settings' ) );
    

    to store settings, if any, into a variable. My problem is that this.settings is a string. I know this, because:

    console.log(typeof this.settings);
    

    returns a string. What I want is for an object to be returned, so I can utilize this.settings like so:

    this.state = this.settings.state;
    

    Does anyone see what I might be doing wrong?

    #161980
    nkrisc
    Participant

    nvm — misread your question

    #162179
    Marteen
    Participant

    @Mottie,

    I’ve got it. The code you suggested works. It was only once I cleared localStorage that it started working. Thanks : )

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.