JavaScript Array Unique function

This functions allows you to eliminate the duplicates from an array of strings, i found several solutions but this one was the best that i came with.

function arrayUnique(arr) {
var temp = {}, c = [], key;
var i = 0, len = arr.length;

for (; i < len; i++) {
temp[arr[i]] = arr[i];
}

for (key in temp) {
c.push(key);
}
return c;
}

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s