Removing Duplicates from Array

Have you ever had an array that want to be distinct? I come across this pretty frequent, one way to solve this is to pass the array into this function below and it will remove all the duplicates and return a distinct array.

function removeDuplicates(a) {
             var r = [];
    o: for (var i = 0, n = a.length; i < n; i++) {
        for (var x = 0, y = r.length; x < y; x++) {
            if (r[x] == a[i]) {
                continue o;
        r[r.length] = a[i];
    return r;
About bwilson 37 Articles
Mobile device specialist currently working as a system analyst, building out an IT infrastructure. I currently focus much of my work on relational databases as well as frameworks. The goal of my work is to continually improve processes and efficiencies.

Be the first to comment

Leave a Reply

Your email address will not be published.