Nodejs Array Contain contains(object)

Here you can find the source of contains(object)

Method Source Code

/*/*from  w ww  .  j a va  2s.c o m*/
 * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
/**
 * This method adds some syntatic sugar around arrays containing an object (instead of using indexOf).
 *
 * @param {Object} object
 * @access public
 */
Array.prototype.contains = function(object) {
  if (this.indexOf(object) !== -1) {
    return true;
  }
  return false;
};

Related

  1. contains(obj)
    Array.prototype.contains = function(obj){
      return (this.indexOf(obj) == -1)?false:true;
    if(!Array.indexOf){
      Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
          if(this[i]==obj) return i;
        return -1;
    ...
    
  2. contains(obj)
    Array.prototype.contains = function(obj)
        return (this.indexOf(obj) > -1);
    
  3. contains(obj)
    Array.prototype.contains = function(obj) {
      for (var i = 0; i < this.length; i++) {
        if (obj == this[i])
          return true;
    };
    
  4. contains(obj, firm)
    Array.prototype.contains = function(obj, firm) {
      firm = firm === true ? true : false;
      var i = this.length;
      while (i--) {
        if ((!firm && this[i] == obj) || this[i] === obj) {
          return true;
      return false;
    ...
    
  5. contains(object)
    Array.prototype.contains = function(object) {
      return (this.indexOf(object) != -1);
    
  6. contains(oneItem)
    Array.prototype.contains = function(oneItem)
      var index = dojo.indexOf(this, oneItem);
      return index != -1;
    
  7. contains(query)
    Array.prototype.contains = function (query)
      function compare(element) 
        return element === query;
      return this.some(compare);
    };
    
  8. contains(search)
    Array.prototype.contains = function(search) {
      return this.indexOf(search) !== -1;
    };
    
  9. contains(str)
    Array.prototype.contains = function(str)
      return this.indexOf(str) != -1;
    };