title: Loop & search through ALL items in localStorage
body: <p>I'm trying to loop through localStorage to get ALL items through <code>localStorage.length</code> that works with my search algorithm. If i change: <code>i &lt; localStorage.length</code> inside the for loop to simply a number, i.e: <code>for (i=0; i&lt;100; i++)</code> instead of: <code>(i=0; i&lt;=localStorage.length-1; i++)</code>, <strong>everthing</strong> works. However, I do realize the problem might lie in the search algorithm. </p>
  
  <p>The code getting all items:</p>
  
  <pre><code>   var name = new Array();
  
     for (var i = 0; i &lt;= localStorage.length - 1; i++) { // i &lt; 100 works perfectly
     key = localStorage.key(i);
     val = localStorage.getItem(key); 
     value = val.split(","); //splitting string inside array to get name
     name[i] = value[1]; // getting name from split string
     }
  </code></pre>
  
  <p>My working (!?) search algorithm:</p>
  
  <pre><code> if (str.length == 0) { 
    document.getElementById("searchResult").innerHTML = "";
    }   
    else {          
        if(str.length &gt; 0) {
            var hint = "";
            for(var i=0; i &lt; name.length; i++) {                
                  if(str.toLowerCase() == (name[i].substr(0, str.length)).toLowerCase()) { //not sure about this line
                      if(hint == "") {                            
                              hint = name[i];                         
                          } else {                            
                              hint = hint + " &lt;br /&gt; " + name[i];                                 
                          }                 
                     }                      
               }            
         }          
  }
  
   if(hint == "") {   
  document.getElementById("searchResult").innerHTML=str + " står inte på listan";     
  } else {        
      document.getElementById("searchResult").innerHTML = hint;       
      }
   }
  </code></pre>
  
  <p>What is wrong with my <code>localStorage.length</code>, or what is wrong with the search algorithm?</p>