title: Javascript check if items in an array are consecutive
body: <p>Say I have an array which holds the values [1,2,3,6,7].</p>
  
  <p>How can I check the array to see if it holds 3 consecutive numbers. For example, the array above holds [1,2,3] so this would return false in my function.</p>
  
  <pre><code>        var currentElement = null;
          var counter = 0;
  
          //check if the array contains 3 or more consecutive numbers:
          for (var i = 0; i &lt; bookedAppArray.length; i++) {
              if ((bookedAppArray[i] != currentElement) &amp;&amp; (bookedAppArray[i] === bookedAppArray[i - 1] + 1)) {
  
                  if (counter &gt; 2) {
                      return true;
                  }
  
                  currentElement = bookedAppArray[i];
                  counter++;
              } else {
                  counter = 1;
              }
          }
  
          if(counter &gt; 2){
              return true;
          } else{
              return false;
          }
  </code></pre>