I'm experimenting with localStorage and am still learning how to access values within the object. I have successfully returned a bunch of objects within localStorage, and now I'm wondering how to turn these comma separated key, value pairs into a legible format. I have tried the replace
method as well as looping through the object, but have had no luck. I'd really appreciate your help.
This is my localStorage output:
{"question":"How do you get close to the president?","your_answer":"buy him some chocolates","answer":"bribe your way in","check":false}{"question":"What is your code name?","your_answer":"John","answer":"Mikhalov","check":false}
I would like for it to look like this:
Question #1: blahblah
Your Answer: blah
Check: Wrong
Question#2: ...
Attempt#1:
if (counter == questions.length-1){
output = ''
for(var i =0; i < localStorage.length; i++){
output += localStorage.getItem(localStorage.key(i)).replace(/"{"/g,"\r\n");
}}
Attempt#2
if (counter == questions.length-1){
for (var key in localStorage){
for (option in key){
console.log(option)
}
}
}