title: Javascript: check if an element from an array is found in another array
body: <p>I have two arrays:</p>
  
  <pre><code>var arr1 = ["1", "2", "3"],
      arr2 = ["2", "5", "8"];
  </code></pre>
  
  <p>What is the best way to determine if any element from arr1 matches any element in arr2?</p>
  
  <p>I'm using jquery, so for now I'm looping arr1 and calling <code>$.inArray(arr1[i], arr2);</code> but I'm curious if there's a better way.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>If anyone is curious about my exact case, it's a google map where I'm looping the markers to see if any of the filtered types are found in the types stored with the marker. If any are found, I show the marker. Otherwise it's hidden. [This code works - will test soon with lots of markers]</p>
  
  <pre><code>var filters = $("#map-search :checked").map(function () {
      return this.value;
  }).get(),
      markerIndex = 0;
  
  for (markerIndex; markerIndex &lt; AKTA.Map.markers.length; markerIndex++) {
  
      var marker = AKTA.Map.markers[markerIndex],
          isVisible = false;
  
      if (filters.length &gt; 0) {
          var filterIndex = 0;
          for (filterIndex; filterIndex &lt; filters.length; filterIndex++) {
              if ($.inArray(filters[filterIndex], marker.types) != -1) {
                  isVisible = true;
                  break;
              }
          }
      }
  
      marker.setVisible(isVisible);
  
  }
  </code></pre>