Nodejs Array Unique unique()

Here you can find the source of unique()

Method Source Code

Array.prototype.unique = function() {
  var a = [];//  w  w  w.  j a v a  2 s  .c  om
  var l = this.length;
  for(var i=0; i<l; i++) {
    for(var j=i+1; j<l; j++) {
      // If this[i] is found later in the array
      if (this[i] === this[j])
        j = ++i;
    }
    a.push(this[i]);
  }
  return a;
};

Related

  1. 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;
    ...
    
  2. unique()
    Array.prototype.unique = function () {
      var obj,
        result = [];
      for (var i = 0, l = this.length; i < l; ++i) {
        obj = this[ i ];
        if ( result.indexOf( obj ) < 0 ) {
          result[ result.length ] = obj;
      return result;
    };
    
  3. unique()
    Array.prototype.unique = function () {
      var r = [];
      o: for (var i = 0, n = this.length; i < n; i++) {
        for (var x = 0, y = r.length; x < y; x++) {
          if (r[x] == this[i]) {
            continue o;
        r[r.length] = this[i];
    ...
    
  4. unique()
    Array.prototype.unique = function(){
        var i,j,len = this.length,tempArr = [],tempLen,state;
        for(i = 0 ; i < len ; i++){
            tempLen = tempArr.length;
            state = true;
            for(j = 0 ; j<tempLen;j++){
                if(this[i] == tempArr[j]){
                    state = false;
            if(state){
                tempArr.push(this[i]);
        return tempArr;
    };
    
  5. unique()
    Array.prototype.unique = function() {
      var r = [];
      this.each(function(key, value) {
        if (!r.contains(value)) {
          r.push(value);
      });
      return r;
    };
    ...
    
  6. unique()
    Array.prototype.unique = function() {
      var aryToReturn = Array();
      for (var i = 0; i < this.length; i++) {
        var val = this[i];
        if (undefined === aryToReturn.findFirst(function() {return this == val})) {
          aryToReturn.push(val);
      return aryToReturn;
    ...
    
  7. unique()
    Array.prototype.unique = function(){
      var new_array = [];
      for (var i=0; i < this.length; i++) {
        if(!new_array.contains(this[i])) new_array.push(this[i]);
      return new_array;
    
  8. unique()
    Array.prototype.unique = function(){
      this.sort((x,y) => x-y);
      for(var i=0; i<this.length-1; ){
        if(this[i]==this[i+1])
          this.splice(i,1);
        else i++;
      return this;
    
  9. unique()
    Array.prototype.unique = function() 
        var h = {};  
        var r = [];
        this.forEach(function (item) { h[item] = true; });
        for (var item in h)
            r.push(item);
        return r;