Nodejs Array Contain contains(v)

Here you can find the source of contains(v)

Method Source Code

// contains() and unique() functions were found here
//http://stackoverflow.com/questions/11246758/how-to-get-unique-values-in-an-array

Array.prototype.contains = function(v) {
  for(var i = 0; i < this.length; i++) {
      if(this[i] === v) return true;
  }/*from  w w w  .ja  v  a2  s.  c  om*/
  return false;
};

Array.prototype.unique = function() {
  var arr = [];
  for(var i = 0; i < this.length; i++) {
      if(!arr.contains(this[i])) {
          arr.push(this[i]);
      }
  }
  return arr;
}


//https://coderwall.com/p/_g3x9q/how-to-check-if-javascript-object-is-empty
function isEmpty(obj) {
    for(var key in obj) {
        if(obj.hasOwnProperty(key))
            return false;
    }
    return true;
}



// function do add hyperlinks
function add_hyperlink(arg, arg2) {
  var out;
  if (arg == null) {
    out = "";
  }
  else {
    out = "<a href=" + arg + ">" + arg2 + "<a/>";
  }
  return out;
}

Related

  1. contains(target)
    Array.prototype.contains = function(target) {
      return this.indexOf(target) != -1;
    };
    
  2. contains(target, ordered)
    Array.prototype.contains = function (target, ordered) {
        ordered = ordered || false;
        var foundAll = true;
        if (ordered) {
            var lastIdx = -1;
            for (var i = 0; i <= target.length - 1; i++) {
                lastIdx = this.indexOf(target[i], lastIdx + 1);
                if (lastIdx == -1) {
                    foundAll = false;
    ...
    
  3. contains(v)
    Array.prototype.contains = function(v) {
        for(var i = 0; i < this.length; i++) {
            if(this[i] === v) return true;
        return false;
    };
    
  4. contains(v)
    Array.prototype.contains = function(v) {
        for(var i = 0; i < this.length; i++) {
            if(this[i] === v) return true;
        return false;
    };
    
  5. contains(v)
    Array.prototype.contains = function (v) 
        for (var i = 0; i < this.length; i++) {
            if (this[i] === v) {
              return true;
        return false;
    };
    ...
    
  6. contains(v)
    Array.prototype.contains = function(v) {
          for(var i = 0; i < this.length; i++) {
              if(this[i] === v) return true;
          return false;
      };
      Array.prototype.unique = function() {
        var arr = [];
        for(var i = 0; i < this.length; i++) {
    ...
    
  7. contains(val)
    #!/usr/bin/js
    arr = [1, 2, 3, 4, 5];
    Array.prototype.contains = function (val) {
      for (var i = 0; i < this.length; i++){
        if (this[i] === val){
          return true;
    console.log(arr.contains(3))
    
  8. contains(value)
    Array.prototype.contains = function(value) {
      return this.indexOf(value) > -1;
    };
    
  9. contains(value)
    Array.prototype.contains = function (value){
        return this.indexOf(value)>=0
    };