Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Storing objects in local storage.

    • 0
    • 3
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 122
    Comment on it

    If you want to store Javascript objects in local storage, you can use HTML5 local storage.

    Here is the code :-

    var dashboard-data = { 'one': 1, 'two': 2, 'three': 3 };
    
    // Put the object into storage
    localStorage.setItem('dashboard-data', JSON.stringify(dashboard-data));
    
    // Retrieve the object from storage
    var proData = localStorage.getItem('proData');
    
    console.log('proData: ', JSON.parse(proData));
    

    setItem will set all the items and getItem will retrieve all the items. Before storing it stringify your object and later parse it when you retrieve it.

    If you are using JSON.stringify() for storing objects, then this function can not serialise private members. This issue can be solved by using the .toString().

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: