Parsing a URL from a document and matching it from an array I need help in improving this script that I have written to parse a URL and check it from an array.

This is what I have done till now: (fiddle)

This is working fine. Was this done correctly? What exactly I need is to search URLs in a list (ul) (which will be a domain specific), and then match if the URL is found in an array (array will have 500+ domains). If it is found then I need to append some text.

Is this function fine to use if there is a long list of domain names in a document and an array has 100+ domains?

Should I use regex to get the domain or is finding it from a CSS selector a good idea?

&lt;div id="links"&gt;
    &lt;ul&gt;
        &lt;li&gt;
            &lt;a href="http://www.azaz.com"&gt;Link 1&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="http://www.azaz.info"&gt;Link 2&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="http://www.123.com"&gt;Link 3&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="http://www.566.com"&gt;Link 4&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="http://www.890.com"&gt;Link 5&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="http://www.azaz.com"&gt;Link 6&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="http://www.azaz.info"&gt;Link 7&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="http://www.123.com"&gt;Link 8&lt;/a&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;



var arr = ['http://www.azaz.com', 'http://www.123.com'];
        $("#links li").each(function () {
        var aa = $(this).find('a').attr('href');
        var found = $.inArray(aa, arr) &gt; -1;
        if(found === true){
            $(this).append("true");
        }
});
Your code is simple and works, so I don't see any need to over-complicate things. It ofcourse depends on the sizes of the lists/data. But 500 doesn't seem so bad, performance wise.

It's good that you decided not to use regular expressions ([source])1
Using a CSS selector seems more appropriate. However it's prone to end up in errors if the site that provides the list changes its css.

In addition, I believe you have a small mistake with your indentation. Perhaps it's just a copy/paste error.

var arr = ['http://www.azaz.com', 'http://www.123.com'];
$("#links li").each(function () {
        var aa = $(this).find('a').attr('href');
        var found = $.inArray(aa, arr) &gt; -1;
        if(found === true){
            $(this).append("true");
        }
});


instead of

var arr = ['http://www.azaz.com', 'http://www.123.com'];
        $("#links li").each(function () {
        var aa = $(this).find('a').attr('href');
        var found = $.inArray(aa, arr) &gt; -1;
        if(found === true){
            $(this).append("true");
        }
});