0

My application has the following Javascript variables:

var bearerToken = "a";
var expirationDate = "b";
var firstName = "c";
var authenticated = true;
var lastName = "d";
var loginMessage = "e";
var name = "f";
var registrationMessage = "g";
var roleId = 1;
var subjectId = 2;
var userName = "h"

I would like to hold a copy of all of these combined in one place in local storage. I only need to be able to do three things to this. Put all of them to the local store. Retrieve all of them from the local store and delete all of them from the local store.

I know how to do it for one at a time but is there a way I could do it for all of them at the same time and store them in one single local storage store.

Note: This is similar to my last question that was perhaps not clear. As I had answers for that I accepted the one that was correct and have created this new question.

3

1 Answer 1

2

You could store the objects wrapped in JSON:

var account = {};
account.bearerToken = "a";
account.expirationDate = "b";
account.firstName = "c";
account.authenticated = true;
account.lastName = "d";
account.loginMessage = "e";
account.name = "f";
account.registrationMessage = "g";
account.roleId = 1;
account.subjectId = 2;
account.userName = "h";

localStorage.setItem('account', JSON.stringify(account));
var loadedAccount = JSON.parse(localStorage.getItem('account'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.