Nodejs Utililty Methods Array Unique

List of utility methods to do Array Unique

Description

The list of methods to do Array Unique are organized into topic(s).

Method

unique()
Array.prototype.unique = function() {
  var json = {};
  var res = [];
  for(var i = 0;i < this.length;i++) {
    if(!json[this[i]]) {
      res.push(this[i]);
      json[this[i]] = true;
  console.log(json);
  return res;
var a = [1,2,3,3,2,1,4,4,0,7,7,7,7,7];
console.log(a.unique());
unique()
Array.prototype.unique = function() {
  var output = {};
  for (var key = 0; key < this.length; key++) {
    output[this[key]] = this[key];
  var results = [];
  for (key in output) {
    var value = output[key];
    results.push(value);
...
unique()
Array.prototype.unique = function(){
    var temp = {};
    for (var i = 0; i < this.length; i++)
        temp[this[i]] = true;
    var r = [];
    for (var k in temp)
        r.push(k);
    return r;
unique()
Array.prototype.unique = function () {
  var tmp = {}, result = [];
  for (var i = 0; i < this.length; i++) {
    if (!tmp[this[i]]) {
      result.push(this[i]);
      tmp[this[i]] = true;
  return result;
...
unique()
var fs = require('fs');
Array.prototype.unique = function() {
  var res = [],
    hash = {};
  for (var i = 0, elem;
    (elem = this[i]) != null; i++) {
    if (!hash[elem]) {
      res.push(elem);
      hash[elem] = true;
...
unique()
Array.prototype.unique = function() {
    var newArr = [],
        origLen = this.length,
        found, x, y;
    for (x = 0; x < origLen; x++) {
        found = undefined;
        for (y = 0; y < newArr.length; y++) {
            if (this[x] === newArr[y]) {
                found = true;
...
unique()
Array.prototype.unique = function() {
    return this.reduce(function(accum, current) {
        if (accum.indexOf(current) < 0) {
            accum.push(current);
        return accum;
    }, []);
};
function mutation(arr) {
...
unique()
Array.prototype.unique = function() {
    var a = this.concat();
    for(var i=0; i<a.length; ++i) {
        for(var j=i+1; j<a.length; ++j) {
            if(a[i] === a[j])
                a.splice(j--, 1);
    return a;
...
unique()
Array.prototype.unique = function()
    this.sort();
    var re=[this[0]];
    for(var i = 1; i < this.length; i++)
        if( this[i] !== re[re.length-1])
            re.push(this[i]);
...
unique()
Array.prototype.unique = function() {
  var n = {},r=[];
  for(var i = 0; i < this.length; i++) {
    if ( this[i] && !n[this[i]]) {
      n[this[i]] = true;
      r.push(this[i]);
  return r;
...