<p>What is the most concise and efficient way to find out if a JavaScript array contains a value?</p>
<p>This is the only way I know to do it:</p>
<pre><code>function contains(a, obj) {
    for (var i = 0; i &lt; a.length; i++) {
        if (a[i] === obj) {
            return true;
        }
    }
    return false;
}
</code></pre>
<p>Is there a better and more concise way to accomplish this?</p>
<p>This is very closely related to Stack Overflow question <em><a href="https://stackoverflow.com/questions/143847/best-way-to-find-an-item-in-a-javascript-array">Best way to find an item in a JavaScript Array?</a></em> which addresses finding objects in an array using <code>indexOf</code>.</p>

If you are using JavaScript 1.6 or later (Firefox 1.5 or later) you can use
Array.indexOf
.  Otherwise, I think you are going to end up with something similar to your original code.