Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the all local storage data?

I have stored some data in local storage. I want to retrieve all local storage details. This is my local storage saving code. This below code saving data usr data

var user_arr=new Array();

function getData()
{  
    for (var i=1; i<=3; i++)
    {  
        var userran=parseInt((Math.random() * (278 - 0+ 1)), 10) + 0;
        localStorage['userCard']=user_arr.push(cards[userran]);
    }
    alert(localStorage['userCard']);
    window.location = 'file:///android_asset/www/game.html';
}

above code works when clicking the button,when I am alerting alert( localStorage['userCard']); it gives the integer value in alert box.

Intially I stored this value in localstorage

I want to get all details in local storage. Can anybody reply how to retrieve this?

hi i getting the data from local storage,my initial local storage data is and it contains 3 cricket player details. and when i alerts the first card using alert the first card details it shows only alert(userCard[0]); it gives only the N as output, how to get all data.

var userCard=[["Nixon", "McLean", "West Indies", 45, 314, 0, 1, "12.07", "37.58", 46, 3, 21, 8, "img/cards/7RBKWQPJAG_NixonMcLean.jpg", 1], ["Brian", "McMillan", "South Africa", 78, 841, 1, 0, "23.36", "36.98", 70, 4, 32, 43, "img/cards/Y9U5UKA60O_BrianMcMillan.jpg", 2], ["Craig", "McMillan", "New Zealand", 197, 4707, 3, 28, "28.18", "35.04", 49, 3, 20, 44, "img/cards/WE0NUNG80C_CraigMcMillan.jpg", 3]] 
like image 643
user3433253 Avatar asked Oct 01 '22 19:10

user3433253


1 Answers

Just type localStorage in your console, you will get all the data stored in local storage. Since it is a json type dictionary, you can simply iterate through all the elements like this:

local = localStorage;
for (var key in local) {
  console.log(key);
//Do something with key, access value by local[key]
}

This will give you all the keys in dict in console.

like image 178
scottydelta Avatar answered Oct 03 '22 09:10

scottydelta