Loop & search through ALL items in localStorage

后端 未结 2 1429
无人共我
无人共我 2021-01-04 06:47

I\'m trying to loop through localStorage to get ALL items through localStorage.length that works with my search algorithm. If i change: i < localStorag

2条回答
  •  迷失自我
    2021-01-04 07:18

    localStorage is an object, not an array. Try for(var i in window.localStorage):

    for(var i in window.localStorage){
       val = localStorage.getItem(i); 
       value = val.split(","); //splitting string inside array to get name
       name[i] = value[1]; // getting name from split string
    }
    

提交回复
热议问题