title: How do I implement a delay on jQuery keyup?
body: <p>I'm making a list filter and want a delay in case the user is a fast typer.  Looking at different solutions for similar questions hasn't helped me and I don't understand the logic they implement.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>$.fn.filterList = function(){   
      var inputFilter = $(this);
      var list        = $('#' + inputFilter.data('list'));
      var listItems    = list.children('li');
  
      inputFilter.keyup(function(){
  
          setTimeout(function () {
              var term = inputFilter.val().toLowerCase();
  
              listItems.each(function(i, e){
                  var city = ($(e).text()).toLowerCase();
  
                  if(city.startsWith(term)){
                      console.log(city);
                  }
              });
          }, 800);
      });
  
  };
  
  $('.my-input').filterList();
  </code></pre>
  
  <p>The problem with this is that it will trigger on each keyup, no matter how fast the user types.</p>
  
  <p>How can I implement a delay so that it does not trigger for each <code>keyup</code>?</p>