Nodejs Array Contain contains(ele)

Here you can find the source of contains(ele)

Method Source Code

Array.prototype.contains = function(ele) {
   for (var i = 0; i < this.length; i++) {
      if (this[i] === ele) return true;
   }//from   ww w  .  ja  va 2s. c o m
   return false;
};
Array.prototype.clear = function() {
   var cnt = this.length;
   this.splice(0, cnt);
};
Array.prototype.findBy = function(key, val) {
   for (var i = 0; i < this.length; i++) {
      if (this[i][key] === val) return this[i];
   }
   return null;
};

String.prototype.substitute = function(dict, sign) {
   var substitution = this;
   if (typeof sign !== "string") 
      sign = "#";
   for (var key in dict) {
      substitution = substitution.replace(new RegExp( sign + '{' + key + '}', 'g'), dict[key])
   }
   return substitution;
};

Related

  1. contains(e)
    Array.prototype.contains = function(e) {
        for (var i = this.length - 1; i >= 0; i--) {
            if (this[i] == e) {
                return true;
        return false;
    };
    
  2. contains(e,ignore)
    Array.prototype.contains  = function(e,ignore)  {  
      if(ignore==undefined) ignore = false;
        for(var i=0;i<this.length;i++){  
        if(ignore){
          if(this[i].toLowerCase() == e.toLowerCase()) 
            return true; 
        }else{
          if(this[i] == e) 
            return true; 
    ...
    
  3. contains(el)
    "use strict";
    Array.prototype.contains = function(el){
      return this.indexOf(el) > -1;
    };
    var rotateArray = function rotateArray(arr){ 
      arr.unshift(arr.pop());
      return arr;
    };
    print(function(input){ 
    ...
    
  4. contains(el)
    Array.prototype.contains = function(el) {
      for(var i = 0; i < this.length; i++) {
        if(this[i] === el) {
          return true;
      return false;
    };
    
  5. contains(el, test)
    Array.prototype.contains = function(el, test) {
        if (test == null) return this.indexOf(el) >= 0;
        for (var i = this.length; --i >= 0;) if (test(this[i], el)) return true;
    };
    
  6. contains(ele)
    Array.prototype.contains = function(ele)
        if(!ele) return false;
        var b=false;
        for(var i=0;i<this.length;i++){
            if(this[i]==ele){
                b=true;
        return b;
    };
    Array.prototype.uniq = function(){
        var a = [];
        this.forEach(function(b){ 
            if(a.indexOf(b) < 0)
                {a[a.length] = b}
        });
        return a;
    };
    Array.prototype.uniqById = function(){
        var a = [];
        var r = [];
        this.forEach(function(b){
            if(b){
                if("id" in b){
                    if(a.indexOf(b.id) < 0){
                        a[a.length] = b.id;
                        r[r.length] = b;
                }else if("_id" in b){
                    if(a.indexOf(b._id) < 0){
                        a[a.length] = b._id;
                        r[r.length] = b;
        });
        return r;
    
  7. contains(elem)
    Array.prototype.contains = function(elem)
      for (var i in this)
        if (this[i] == elem) return true;
      return false;
    };
    
  8. contains(elem)
    Array.prototype.contains = function(elem) {
        return this.indexOf(elem) != -1;
    
  9. contains(elem)
    Array.prototype.contains = function (elem) {
      for (var i = 0; i < this.length; i++) {
        if (this[i] == elem) {
          return true;
      return false;