Nodejs Array Unique unique()

Here you can find the source of unique()

Method Source Code

Array.prototype.unique=function(){

      return this.filter(function (x,i,self){

            return self.indexOf(x)===i;
      });/*from  www  .  ja va 2 s  .c  om*/
}

Related

  1. uniq()
    Array.prototype.uniq = function() {
      var uniqArray = [];
      for (var i = 0; i < this.length; i++) {
        if (uniqArray.indexOf(this[i]) === -1) {
          uniqArray.push(this[i]);
      return uniqArray;
    };
    ...
    
  2. unique
    Array.prototype.unique =
      function() {
        var a = [];
        var l = this.length;
        for(var i=0; i<l; i++) {
          for(var j=i+1; j<l; j++) {
            if (this[i] === this[j])
              j = ++i;
          a.push(this[i]);
        return a;
      };
    
  3. unique
    Array.prototype.unique =
      function() {
        var a = [];
        var l = this.length;
        for(var i=0; i<l; i++) {
          for(var j=i+1; j<l; j++) {
            if (this[i] === this[j])
              j = ++i;
          a.push(this[i]);
        return a;
      };
      Array.prototype.clean = function(deleteValue) {
        for (var i = 0; i < this.length; i++) {
          if (this[i] == deleteValue) {         
            this.splice(i, 1);
            i--;
        return this;
      };  
    String.prototype.contains = function(it) { return this.indexOf(it) != -1; };
    
  4. unique
    Array.prototype.unique =
      function() {
        var a = [];
        var l = this.length;
        for(var i=0; i<l; i++) {
          for(var j=i+1; j<l; j++) {
            if (this[i] === this[j])
              j = ++i;
          a.push(this[i]);
        return a;
      };
    Date.prototype.today = function () {
        return ((this.getDate() < 10)?"0":"") + this.getDate() +"."+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"."+ this.getFullYear();
    Date.prototype.timeNow = function () {
         return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
    
  5. unique()
    Array.prototype.unique = function() {
        return [... new Set(this)]
    
  6. unique()
    Array.prototype.unique = function() {
       return this.sort().reduce( (a,e) => e === a[a.length-1] ? a : (a.push(e), a), [] )
    
  7. unique()
    Array.prototype.unique=function(){
      var n=[];
      for(var i=0;i<this.length;i++){
        if(n.indexOf(this[i])==-1) n.push(this[i]);
      return n;
    
  8. unique()
    Array.prototype.unique = function (){
      return Array.from(new Set(this));
    let testArray = [1,2,5,4,2,6,1];
    console.log(testArray.unique());
    
  9. unique()
    Array.prototype.unique = function() {
      var o = {}, i, l = this.length, r = [];
      for(i=0; i<l;i+=1) o[this[i]] = this[i];
      for(i in o) r.push(o[i]);
      return r;
    };