title: JavaScript Undefined when alert(array.length) is called
body: <p>Lately I have been trying to create a webpage with a search feature. My way of implementing this, while not the fastest or most elegant, should work in theory. All it does is split the search term into a list, the delimiter being a space, and then splits the keywords (in dictionary format, with the value being a download link, and with the key being the &quot;keywords&quot; I was referring to) and finally, it has an outer loop looping through the keys (being split each iteration into a list), and an inner loop looping through the words input through the input field. If a word in the search field matches one keyword of the key words list, then that key from the dictionary gets a score of +1.</p>
  <p>This should sort the keys into order of best result to worst, and then the code can continue on to process all this information and display links to the downloadable files (the point of the webpage is to supply downloads to old software [of which I have collected over  the years] etc.). However, when I run the program, whenever the <code>alert(ranking.length)</code> function is called, all I get is <code>undefined</code> in the output window.</p>
  <p>Here is the code. (The <code>search()</code> function is called whenever the search button is pressed):</p>
  <pre class="lang-js prettyprint-override"><code>var kw_href = {
              &quot;windows&quot;:[&quot;windows3.1.7z&quot;],
              &quot;ms dos 6.22&quot;:[&quot;ms-dos 6.22.7z&quot;]
          }
          function search(){
              var element = document.getElementById(&quot;search_area&quot;);
              var search_term = element.value.toLowerCase();
              
              var s_tags = search_term.split(&quot; &quot;);
              var keys = Object.keys(kw_href);
  
              ranking = {
                  &quot;windows&quot;:0,
                  &quot;ms dos 6.22&quot;:0
              };
  
              for (i = 0; i &lt; keys.length; i++){
                  keywords_arr = keys[i].split(&quot; &quot;);
                  for (x = 0; x &lt; s_tags.length; x++){
                      if (keywords_arr.includes(s_tags[x])){
                          ranking[keys[i]] = ranking[keys[i]] + 1;
                      }
                  }
              }
              // now we have a results list with the best results. Lets sort them into order.
              alert(ranking.length);
          }
  </code></pre>
  <h2>Edit</h2>
  <p><code>alert(ranking.length)</code> line is for debugging purposes only, and I was not specifically trying to find the length.</p>