最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to retrieve the all local storage data? - Stack Overflow

programmeradmin3浏览0评论

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]] 

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]] 
Share Improve this question edited May 14, 2014 at 12:20 user3433253 asked May 14, 2014 at 10:45 user3433253user3433253 531 silver badge7 bronze badges 2
  • store your array as localstorage.myArray=[.......], and retrieve it with the same name localstorage.myArray – Vikram Jakkampudi Commented May 14, 2014 at 11:01
  • i wrote this above code inside html, because initially i load the some card data from javascript variable to local storage. how to get this localstorage data to another js file and how to retrieve it – user3433253 Commented May 14, 2014 at 11:12
Add a ment  | 

2 Answers 2

Reset to default 4

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.

localStorage is an object

you can directly use this object as a normal object, like any other

you can check browser support by using

typeof(Storage) if it is returned 'undefined' your browser does not support localStorage/sessionStorage

发布评论

评论列表(0)

  1. 暂无评论