title: Problem comparing input to array using slice function
body: <p>I am creating a search bar, that filters an array with French city names that match the input value with each keyup. I am getting some results back (using the console log), but the results are not what I expect and the IF condition I am using doesn't seem to be functioning...</p>
  
  <p>Based in JavaScript and a little jQuery to get my list of cities from a text file, I've tried using <code>indexOf</code> and <code>match</code> function, but using <code>slice()</code> seems to have got me the furthest. I'm missing something somewhere to push the matched results into a new variable/array.</p>
  
  <pre><code>var cityArray = [];
  $.get("liste.txt", function (data) {
      cityArray = data.split("\n").sort();
      console.log(cityArray);
  });
  
  $("#myInput").keyup(function () {
      var searchedWord = $(this).val();
      var counter = searchedWord.length;
      var result = [];
      console.log(searchedWord);
      // console.log(typeof searchedWord);
      // console.log(counter);
      var matchedCities = 0;
      if (counter &lt; 3) {
          return;
      }
      for (var i = 0; i &lt; 100; i++) {
          var city = cityArray.slice(0, cityArray.length);
  
          console.log(city[i].slice(0, searchedWord.length));
          if (city[i].slice(0, searchedWord.length) == searchedWord) {
              result.push(city[i]);
              console.log(result);
              matchedCities++;
              console.log(matchedCities);
              if (matchedCities &gt; 5) {
                  break;
              }
          }
      }
  });
  </code></pre>
  
  <p>So I am expecting to see matched cities with the input, in the console log. BUT, the function seems to break down before then as the <code>result</code> and <code>matchedCities</code> variables don't seem to change even when I know I have typed a city that is in the list.</p>