Nodejs Array Unique unique()

Here you can find the source of unique()

Method Source Code

Array.prototype.unique = function () {
  var arr = this;
  return this.filter(function (el, idx) {
    return arr.lastIndexOf(el) === idx;
  });//from   ww  w  .jav  a 2s. c  om
};

Related

  1. unique()
    Array.prototype.unique = function() {
      var arr = [this[0]];
      for (var i = 1; i < this.length; i++) {
        if ( arr.indexOf (this[i]) === -1) {
          arr.push(this[i]);
      return arr;
    var arr = [1, 2, 1, 3, 5, 3, 5, '5'];
    console.log(arr.unique());
    console.time();
    var unique2 = function(arr) {
      var 
        ary = [],
        i = 0,
        key;
      for (; key = arr[i++]; ) {
        if ( ary.indexOf(key) === -1 ) {
          ary.push(key);
      return ary;
    console.log(unique2(arr));
    console.timeEnd();
    
  2. unique()
    Array.prototype.unique = function () {
        var r = new Array();
        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;
    ...
    
  3. unique()
    Array.prototype.unique = function() {
      var arr = [];
      for(var i = 0; i < this.length; i++) {
        if(arr.indexOf(this[i]) === -1) {
          arr.push(this[i]);
      return arr;
    };
    ...
    
  4. 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;
    
  5. unique()
    Array.prototype.unique = function () { 
      return this.filter((a, i) => this.indexOf(a) === i) 
    
  6. 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];
    ...
    
  7. 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;
    ...
    
  8. unique()
    function getDomain(address) {
      return address.substring(address.indexOf('@') + 1);
    function cleanPhoneNo(str) {
      return str.replace(/[^\d]/g, '');
    function escapeRegExp(str) {
      var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); 
      return str.replace(specials, "\\$&");
    ...
    
  9. unique()
    function SecondGreatLow(arr) {
     arr.sort(function (a,b){
       return a-b;
     });
     arr = arr.unique();
     if (arr.length == 2){
        return arr[1]+ " "+ arr[0];
     } else {
        return arr[1]+ " " + arr[arr.length-2];
    ...