title: How to stop javascript loop once match is found in array
body: <p>I tried finding some fixes, but don't seem to be finding what I'm looking for. Maybe its my wording.</p>
  
  <p>So I have this form that once it submits with a 5 digit zip code it checks an array for a matching value, once its matches I want it to show a success message and if It doesn't match then return No match, but currently it returns the message as many time as the array has. I'm still fairly new to JavaScript so any help would be greatly appreciated. Thanks in Advance!</p>
  
  <p><strong>JavaScript:</strong></p>
  
  <pre><code>&lt;script&gt;
  function getZip(e) {
      e.preventDefault();
      var zip = document.getElementById('zip').value; // Gets the value from the text field "zip" on the form.
      var result = ["48650", "48611", "48746", "48614", "48706"];
  
      for (var i = 0; i &lt; result.length; i++) {
          //console.log(result[i]);
  
          //if (zip.length == 5 &amp;&amp; zip == result[i]){
          if (zip == result[i]) {
              console.log(zip + " is = to " + result[i]);
              alert('Match ' + zip);
  
          } else if (result[i] != zip) {
              alert("No Match1");
              console.log(zip + " is != to " + result[i]);
  
          } else {
              alert("No Match2");
              console.log(zip + " is != to " + result[i]);
          }
          //return false;
      }
      if (zip === "") { // Checks if the text field "zip" is empty, if so it returns an error message.
          alert('Please enter a zip code!');
  
      } else if (zip.length &gt; 5) {
          alert("Please enter a valid 5 digit numeric zip code.");
  
      } else if (zip.length &lt; 5) {
          alert("Please enter a valid 5 digit numeric zip code.");
  
      } else if (isNaN(zip)) { // Checks if the text field "zip" for alphabetic characters. The "isNaN" function is to determine if a value does not convert to a number, if so it returns an error message.
          alert("Please enter a numeric value.");
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>Form:</strong></p>
  
  <pre><code>&lt;div class="searchZip"&gt;
      &lt;p&gt;Please enter your zip code for availability&lt;/p&gt;
      &lt;form&gt;
          &lt;input type="text" name="zip" id="zip" placeholder="Zip Code"&gt;
          &lt;button onclick="getZip(event);"&gt;Check&lt;/button&gt;
      &lt;/form&gt;
      &lt;p id="display"&gt;&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>