Using each method | var temp = [];
$.each(array, function(i, el) {
if ($.inArray(el, temp) === -1) temp.push(el);
});
return temp;
| ready |
Using for method #1 | var temp = {};
for (var i = 0; i < array.length; i++) {
temp[array[i]] = array[i];
}
c = [];
for (var key in temp) {
c.push(key);
}
return c;
| ready |
Using for method #2 | var temp = {};
for (var i = 0; i < array.length; i++)
temp[array[i]] = true;
var r = [];
for (var k in temp)
r.push(k);
return r;
| ready |
Using for object | var u = {},
a = [],
v;
for (var i = 0, l = array.length; i < l; ++i) {
v = array[i];
if (u.hasOwnProperty(v)) {
continue;
}
a.push(v);
u[v] = 1;
}
return a;
| ready |
Map | var temp = {},
result = [],
x;
for (var i = array.length; i >= 0; i--) {
x = array[i];
if (!(x in temp)) {
temp[x] = 1;
result.push(x);
}
}
return result;
| ready |
sort & step |
for(var b=array.sort(), i=b.length, l=b[--i], r=[l]; i--;)
if(b[i] !== l) r.push(l = b[i]);
return r;
| ready |
modified map |
for (var n = array.length, result = [array[n--]], i; n--;) {
i = array[n];
if (!(i in result)) result.push(i);
}
return result;
| ready |
Double While | var b;
var c;
b = array.length;
while (c = --b) while (c--) array[b] !== array[c] || array.splice(c, 1);
return array;
| ready |
Sort and filter |
var previous;
array.sort();
return array.filter(function(item) {
var result = item !== previous;
previous = item;
return result;
});
| ready |
filter with indexOf | return array.filter(function(item, index, array) {
return array.indexOf(item) >= index;
});
| ready |
filter with indexOf (keeping last occurrence) |
return array.filter(function(item, index, array) {
return array.indexOf(item, index + 1) === -1;
});
| ready |
map (+ forEach) |
var temp = {},
result = [];
array.forEach(function(item) {
if (!(item in temp)) {
temp[item] = 1;
result.push(item);
}
});
return result;
| ready |
map (different key check) | var temp = {},
result = [],
x;
for (var i = array.length; i >= 0; i--) {
x = array[i];
if (!temp[x]) {
temp[x] = true;
result.push(x);
}
}
return result;
| ready |
map (growing loop) | var temp = {},
result = [],
x;
for (var i = 0; i < array.length; i++) {
x = array[i];
if (!(x in temp)) {
temp[x] = 1;
result.push(x);
}
}
return result;
| ready |
ES6 Set | return Array.from(new Set(array));
| ready |
map (using while and replaces pushes with indexing) -- reverses order | var indexes = {}
, result = []
, k = array.length
, i = 0
, v
;
while ( k-- ) {
( (v = array[k]) in indexes )
|| (result[i++] = (indexes[v] = v))
}
return result;
| ready |