How to search through an array in Javascript?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/840781/easiest-way-to-find-duplicate-values-in-a-javascript-array">Easiest way to find duplicate values in a JavaScript array</a>  </p>
</blockquote>



<p>I am looking to find if two values are the same in an Array. I have written the following code:</p>

<pre><code>function validatePassTimeFields(passtimes) {
    var success = true; 
    var length = passtimes.length;
    var hashMap = new Object();
    for (var j=0; j&lt;length; j++) {
        if(hashMap[passtimes[j].value]==1) {
            success = false;
            alert("Duplicate Found");
            break;
        }
        hashMap[passtimes[j].value]=1;
    }
    return success;
}
</code></pre>

<p>I am new to Javascript, so I tried using HashMap like to find if there is any duplicate. IS it the best way of finding a duplicate in JavaScript? or I can optimize it?</p>
