Q:

How to remove duplicate domains from a URL list using javascript

I am stuck at a rather simple problem - removing duplicate domains from a list of URL's, using javascript.
Here's what I am currently doing:
I have an array called 'list' which has the list of url's. I work on that to extract the domains, and put them in a new array called 'domain'.
Then I use two for loops to go through the entire list and check for duplicate domains. If the domains match, I splice the duplicate one out. But it seems to be removing too many, and I am pretty sure I am doing something wrong. Can somebody tell me what I am doing wrong, or suggest a simpler/better way of doing it?
for (i=0; i<list.length; i++) {

    for (j=i+1; j<list.length; j++) {

        if (domain[i] == domain[j]) {

            console.log('REMOVING:');
            console.log(i + '. ' + list2[i]);
            console.log(j + '. ' + list2[j]);
            console.log(domain[i]);
            console.log(domain[j]);

            list.splice(j,1);

        }
    }
}

This is not a 'how to remove duplicates from an array' question. As I have a list of URL's, and need to check for - and remove, only the duplicate 'domains'. So suppose I have 4 URL's from youtube, I need to keep only the first one and remove the rest.

A:

ES5: filter the array and only include if the current item's index is equal to its index in the array:
list.filter(function(elem, pos, arr) {
   return arr.indexOf(elem) === pos;
});

ES6: use a Set
const uniqueDomains = [ ...new Set(list) ];

or if you can't use the spread operator:
new Set(list).toJSON()

