0

I want to store my radio button values in an object on local storage with index of the object as key of it. What should I do to make fix size array? Also I want to set that object as initial value of my state. I have tried some things, but it does not work out.

2 Answers 2

0
var obj = {'one': 1,'two': 2,'three': 3 };

localStorage.setItem('testObject', JSON.stringify(testObject));

var retrievedObject = localStorage.getItem('testObject');

console.log('retrievedObject: ', JSON.parse(retrievedObject));
Sign up to request clarification or add additional context in comments.

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
I am making an quiz app in which I want to save my selected answers on localstorage but when i come to previous question to reset my answer and then go onto next question then i don't want new item added in my object.
0

This is how you make an array with the fix length 5 and all element as A.

const LEN = 5;
const arr = new Array(LEN).fill(A);
localStorage.setItem("ID", JSON.stringify(arr))

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.