Home > JavaScript, Mini-tips, Programación, Tips > Remove duplicated elements, Array JavaScript

Remove duplicated elements, Array JavaScript

I got this piece of code from stackoverflow, and im just sharing this cus this is something that I am usually looking for :P and this will save some time :), I am adding the source if you want to check out more options on how to do this.

function getDistinctArray(a) {
var d = {};
return a.filter(function(e) {
var h = e.valueOf(), i = d[h];
d[h] = true;
return !i;


  1. Simon Orozco
    March 20, 2013 at 12:59

    Nice piece of code gordito

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: