I have data saved in "localStorage".
Now i'd like to put that data into a JS array so that i can sort it and then output it.
//CREATE ARRAY
var localStorage_arr = [];
//LOOP THREW localStorage
Object.keys(localStorage).forEach(function(key){
//GET LOCALSTORAGE ITEM
var item = JSON.parse(localStorage.getItem(key));
//SET ARRAY KEY AND CREATE MULTIDIMENSIONAL ARRAY
localStorage_arr[key] = [];
//ADD SOME DATA
localStorage_arr[key]['art_id'] = item.art_id;
localStorage_arr[key]['art_nr'] = item.art_nr;
});
//SORT ARRAY
localStorage_arr.sort();
//CONSOLE.LOG ARRAY
console.log(localStorage_arr)
//IN LOG:
[1614851259727: Array(0), 1614849876677: Array(0), 1614849865169: Array(0), 1614849873617: Array(0), 1614849870613: Array(0)]
1614849865169: [art_id: 2110, art_nr: "01", article: "Test", balance: 362, …]
1614849870613: [art_id: 2110, art_nr: "01", article: "Test", balance: 362, …]
1614849873617: [art_id: 2110, art_nr: "01", article: "Test", balance: 362, …]
1614849876677: [art_id: 2110, art_nr: "01", article: "Test", balance: 362, …]
1614851259727: [art_id: 2110, art_nr: "01", article: "Test", balance: 380, …]
Question one: Why does it say: Array(0) ?
Later i try to loop threw my array:
//LOOP THREW localStorage_arr
localStorage_arr.forEach(function (item, index) {
//console.log(item, index);
});
//IN LOG: nothing..
Why can't i loop threw the array?