Finding a single, or multiple values from a string of arrays in Javascript <p>I'm trying to search through my array for whatever number I put in, but it doesn't work as intended. </p> <p>In external javascript:</p> <pre><code>window.onload = startup; function startup() { runArraySequence () { writeArray.onclick = findArray; } } var array = [5,3,9,12,19,15,13,6,9,2,4,7,8,17]; function findArray () { //The following script is a part of a 12 "else if" radio button form. if (arrayRad11.checked) { var searchNumber = document.getElementById("arrayValue").value; var arrayResult = -1; for (var i=0; i &lt; array.length; i++) { if (array[i] === searchNumber) { i = arrayResult; } if (arrayResult &lt; 0) { msg6.innerHTML = "Found number " + searchNumber + ", " + arrayResult + " times."; } } } } </code></pre> <p>HTML code:</p> <pre><code>&lt;div&gt; &lt;form&gt; &lt;input type="radio" id="arrayRad11" name="array" value="11"&gt;Find Number:&lt;/input&gt; &lt;input type="number" id="arrayValue" placeholder="Find Array Number"&gt;&lt;/input&gt;&lt;br /&gt; &lt;input type="button" id="writeArray" value="Skriv tall"&gt;&lt;/input&gt; &lt;input type="button" value="Reset" onClick="window.location.reload()"&gt;&lt;/input&gt; &lt;/form&gt; &lt;p id="msg6"&gt;&lt;/p&gt; &lt;/div&gt; </code></pre> <p>Also uploaded to <a href="http://jsfiddle.net/v48am4jo/5/" rel="nofollow">jsfiddle</a></p>