Difficulty writing a function to extract URL from array
<p>I'm trying to extract a URL from an array using JS but my code doesn't seem to be returning anything.</p>

<p>Would appreciate any help!</p>

<pre><code>var pages = [
    "www.facebook.com|Facebook",
    "www.twitter.com|Twitter",
    "www.google.co.uk|Google"
    ];

function url1_m1(pages, pattern) {
    var URL = '' // variable ready to accept URL
    for (var i = 0; i &lt; pages[i].length; i++) {
        // for each character in the chosen page
        if (pages[i].substr(i, 4) == "www.") {
            // check to see if a URL is there
            while (pages[i].substr(i, 1) != "|") {
                // if so then lets assemble the URL up to the colon
                URL = URL + pages[i].substr(i, 1);
                i++;
            }
        }
    }
    return (URL);
    // let the user know the result
}
alert(url1_m1(pages, "twitter")); // should return www.twitter.com
</code></pre>
