Nodejs Array Unique unique()

Here you can find the source of unique()

Method Source Code

Array.prototype.unique = function(){
    var u = {}, a = [];
    for(var i = 0, l = this.length; i < l; ++i){
        if(u.hasOwnProperty(this[i])) {
            continue;//from  w  w w . ja  va  2s  . c  o  m
        }
        a.push(this[i]);
        u[this[i]] = 1;
    }
    return a;
}

Related

  1. unique()
    Array.prototype.unique = function(){
      'use strict';
      this.sort();
      var ret = [this[0]];
      for(var index=0; index < this.length; index++){
        if(this[index] != ret[ret.length - 1]){
          ret.push(this[index]);
      return ret;
    };
    
  2. unique()
    Array.prototype.unique = function()
        var n = {},r=[];
        for(var i = 0; i < this.length; i++)
            if (!n[this[i]])
                n[this[i]] = true;
                r.push(this[i]);
    ...
    
  3. 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;
    ...
    
  4. 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;
    ...
    
  5. 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]] = 1;
      return res;
    var a = [1,2,3,3,2,1,4,4,0,7];
    console.log(a.unique());
    
  6. unique()
    Array.prototype.unique = function () {
        var exist = {},
            i;
        for (i = 0; i < this.length; i++) {
            if (exist[this[i]]) {
                this.splice(i, 1);
                i -= 1;
            } else {
                exist[this[i]] = true;
    ...
    
  7. unique()
    Array.prototype.unique = function(){
       var u = {}, a = [];
       for(var i = 0, l = this.length; i < l; ++i){
          if(u.hasOwnProperty(this[i])) {
             continue;
          a.push(this[i]);
          u[this[i]] = 1;
       return a;
    
  8. unique()
    Array.prototype.unique = function(){
      var new_array = [];
      var index = 0;
      var value = null;
      for( count=0; count < this.length; count++){
        value = this[count];
        if( new_array.indexOf(value)==-1 ){
          new_array[index++] = value;
      return new_array;
    };
    
  9. unique()
    Array.prototype.unique = function () {
        var arrVal = this;
        var uniqueArr = [];
        for (var i = arrVal.length; i--; ) {
            var val = arrVal[i];
            if ($.inArray(val, uniqueArr) === -1) {
                uniqueArr.unshift(val);
        return uniqueArr;