Javascript: matching a dynamic string against an array
<p>I'm attempting to teach myself javascript. I chose something I assumed was simple, but ran into problems relatively quickly. </p>

<p>I'm attempting to search a string for another string given by the user. </p>

<p>My code so far is: </p>

<pre><code>var source = "XREs2qqAQfjr6NZs6H5wkZdOES5mikexRkOPsj6grQiYNZfFoqXI4Nnc1iONKVrA";
var searchString = []; //the users input
searchString = prompt("Enter search string");
var hits = [];
var one = 0;
var two = 0;
var k = 0;

var sourceSearch = function(text) {
    for(i = 0; i &lt; source.length; i++) { //for each character in the source
        if(source[i] === searchString[0]) {  //if a character in source matches the first element in the users input
            one  = source.indexOf(i); //confused from here on
            for(p = searchString.length; p &gt; 0; p--) {

            }                    
        }
    }
};


sourceSearch(searchString);
</code></pre>

<p>My idea was:</p>

<ul>
<li>check to see if the first loop finds a character that matches the first character in the user input</li>
<li>if it matches, check to see if the next X characters after the first match the next X characters in the source string</li>
<li>if they all match, push them to the hits array</li>
</ul>

<p>My problem: I have no idea how to iterate along the arrays without nesting quite a few if statements, and even then, that wouldn't be sufficient, considering I want the program to work with any input.</p>

<p>Any ideas would be helpful. Thanks very much in advance. </p>

<p>Note: There are a few un-used variables from ideas I was testing, but I couldn't make them work. </p>
