Nodejs Array Unique unique(arr)

Here you can find the source of unique(arr)

Method Source Code

function unique(arr) {
  var result = [],
    hash = {};/* w  w w . j  a  v  a 2s . co m*/
  for (var i = 0, elem;
    (elem = arr[i]) != null; i++) {
    if (!hash[elem]) {
      result.push(elem);
      hash[elem] = true;
    }
  }
  return result;
}

Related

  1. uniquelize()
    Array.prototype.uniquelize = function() {
      var array = new Array();
      var length = this.length;
      for (var i = 0; i < length; i++) {
        if (!array.inArray(this[i])) {
          array.push(this[i]);
      return array;
    ...
    
  2. uniquelize()
    Array.prototype.uniquelize = function(){
         var ra = new Array();
         for(var i = 0; i < this.length; i ++){
             if(!ra.contains(this[i])){
                ra.push(this[i]);
         return ra;
    };
    ...
    
  3. uniquelize()
    Array.prototype.uniquelize = function () {
        var tmp = {},
            ret = [];
        for (var i = 0, j = this.length; i < j; i++) {
            if (!tmp[this[i]]) {
                tmp[this[i]] = 1;
                ret.push(this[i]);
        return ret;
    
  4. uniquelizeES6()
    Array.prototype.uniquelizeES6=function(){
        return  [...new Set(this)]
    
  5. uniquer()
    var toEnter = (1,2,3,3,3,4,5,6,'this','this','that');
    Array.prototype.uniquer = function () {
        var uniqueValues = [];
        var checkUniqueValues = function (toBeChecked) {   
          for (var i = 0; i < uniqueValues.length; i++) {
            if (toBeChecked === uniqueValues[i]) {
              return true;
          return false;
        };
        for (var i = 0; i < this.length; i++) { 
          if(checkUniqueValues(this[i]) === false) { 
            uniqueValues.push(this[i]); 
        return uniqueValues;
    };
    var testArray = [1,2,3,3,3,3,3]
    var finalProduct = testArray.uniquer();
    module.exports.finalProduct = finalProduct;
    
  6. uniteUnique(arr1, arr2, arr3)
    function uniteUnique(arr1, arr2, arr3) {
      var resultArr = [];
      for (var i = 0; i < arguments.length; i++) {
        for (var j = 0; j < arguments[i].length; j++) {
          if (resultArr.indexOf(arguments[i][j]) === -1) {
              resultArr.push(arguments[i][j]);
      return resultArr;
    uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
    
  7. Unique()
    Array.prototype.Unique = function(){
      var unique = [];
      this.forEach(function(e, i, a){
        if(!unique.includes(e)){
          unique.push(e);
      });
      return unique;
    };
    ...
    
  8. Unique()
    function array_keys_true(array){
      var result = [];
      for(element in array)
        if(element)
          result.push(array[element]);
      return result;
    function array_remove(arr) {
      var what, a = arguments, L = a.length, ax;
    ...