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
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
}
Problem now SOLVED. The issue was that each time data was saved to localStorage, one extra empty item was stored at the bottom of the local db as a consequence of an incorrectly written for loop (in the setItem part.) arrayIndex < guestData.length should have been arrayIndex < guestData.length-1. arrayIndex < guestData.length-1 stores all items without creating an empty item at the bottom of the database which later messed up the search algorithm, as the last value to be search was undefined (the empty item).