0

i want to know how to do for the keys be like: 1, 2, 3... For now, this is my code:

    <input type='text' id='provedor' />
<input type='text' id='login' />
<input type='text' id='senha' />
<input type='text' id='link' />
<input type='text' id='id' />
<button onclick="save()" type="button">Save</button>
<script>function save(){
var json = {};
    json.login = $('#login').val();
    json.senha = $('#senha').val();
    json.link = $('#link').val();
    json.id = $('#id').val();
    var provedor = document.getElementById('provedor').value;
    localStorage.setItem(provedor, JSON.stringify(json));}    

I need this to list the results. Please help me. Thank you a lot!!

vitor
  • 1

1 Answers1

0

If you want all the keys and results from the localStorage:

  localStorage.setItem("a", 1);
  localStorage.setItem("b", 1);
  localStorage.setItem("c", 1);
  localStorage.setItem("d", 1);

    var store = [];
    for (var i = 0; i < localStorage.length; i++)
    {         
        store.push([localStorage.key(i), localStorage.getItem(localStorage.key(i))]);
    }
    console.log(JSON.stringify(store));

http://jsfiddle.net/0ehukdcu/1/

Mouser
  • 13,132
  • 3
  • 28
  • 54