title: Best way to find if an item is in a JavaScript array?
body: <p>What is the best way to find if an object is in an array?</p>
  
  <p>This is the best way I know:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function include(arr, obj) {
    for (var i = 0; i &lt; arr.length; i++) {
      if (arr[i] == obj) return true;
    }
  }
  
  console.log(include([1, 2, 3, 4], 3)); // true
  console.log(include([1, 2, 3, 4], 6)); // undefined</code></pre>
  </div>
  </div>
  </p>