Nodejs Array Contain contains(value)

Here you can find the source of contains(value)

Method Source Code

// This file is part of Ambience Stage
// Copyright 2012-2013 Jakob Kallin
// License: GNU GPL (http://www.gnu.org/licenses/gpl-3.0.txt)

Array.prototype.contains = function(value) {
   return this.indexOf(value) !== -1;
};

Array.prototype.remove = function(value) {
   var index = this.indexOf(value);
   if ( index !== -1 ) {
      this.splice(index, 1);//  w  w  w  .j  a v a 2  s  .c o m
   }
};

Array.prototype.clear = function() {
   this.splice(0);
};

Array.prototype.first = function(predicate) {
   for ( var i = 0; i < this.length; i++ ) {
      var value = this[i];
      if ( predicate(value) ) {
         return value;
      }
   }
   return null;
};

Array.prototype.randomIndex = function() {
   return Math.floor(Math.random() * this.length);
};

String.prototype.contains = function(substring) {
   return this.indexOf(substring) !== -1;
};

String.prototype.startsWith = function(prefix) {
   return this.indexOf(prefix) === 0;
};

String.prototype.endsWith = function(suffix) {
   return this.lastIndexOf(suffix) === this.length - suffix.length;
};

Related

  1. contains(value)
    Array.prototype.contains = function(value) {
      return this.indexOf(value) > -1;
    };
    
  2. contains(value)
    Array.prototype.contains = function (value){
        return this.indexOf(value)>=0
    };
    
  3. contains(value)
    Array.prototype.contains = function(value) {
        return Array.prototype.indexOf.call(this, value) !== -1;
    };
    
  4. contains(value)
    Array.prototype.contains = function(value) {
        return (this.indexOf(value) > -1);
    
  5. contains(value)
    "use strict";
    Array.prototype.contains = function(value){
      var n = this.length
      for (var i = 0; i < n; i++){
        if (this[i] == value) return true
      return false
    
  6. contains(value)
    Array.prototype.contains = function(value) {
      for(var i=0; i < this.length; i++) {
        if(this[i] === value)
              return true;
      return false;
    };
    
  7. contains(what)
    Array.prototype.contains = function (what) {
      var contains = false;
      if (typeof what !== 'function') {
        this.forEach(function (item) {
          if (contains) return;
          contains = (item === what);
        });
        return contains;
      this.forEach(function (item) {
        if (contains) return;
        contains = what(item);
      });
      return contains;
    };
    
  8. contains(x)
    Array.prototype.contains=function(x){
     for(i in this){
       if((x.city==this[i].city || x.firstName==this[i].firstname || x.lastName==this[i].lastname))
         return true;
     return false;
    
  9. contains(x)
    Array.prototype.contains = function (x) {
        return this.indexOf(x) > -1;
    };