Nodejs Array In inArray(comparer)

Here you can find the source of inArray(comparer)

Method Source Code

// check if an element exists in array using a comparer function
// comparer : function(currentElement)
Array.prototype.inArray = function(comparer) {
  for (var i = 0; i < this.length; i++) {
    if (comparer(this[i])) return true;
  }//from  w  ww  .j  a  v a  2  s  . c om
  return false;
};

// adds an element to the array if it does not already exist using a comparer
// function
Array.prototype.pushIfNotExist = function(element, comparer) {
  if (!this.inArray(comparer)) {
    this.push(element);
    return true;
  }
  return false;
};


// find index of object in array given some property value
function arrayObjectIndexOf(myArray, property, searchTerm) {
  for (var i = 0, len = myArray.length; i < len; i++) {
    if (myArray[i][property] === searchTerm) return i;
  }
  return -1;
}

// find index of item in array
function arrayIndexOf(myArray, searchTerm) {
  for (var i = 0, len = myArray.length; i < len; i++) {
    if (myArray[i] === searchTerm) return i;
  }
  return -1;
}

Related

  1. inArray()
    Array.prototype.inArray = function() {
        for(var j in this) {
            if(this[j] == arguments[0]) {
                return true;
        return false;
    
  2. inArray()
    Array.prototype.inArray = function()
      for (var j in this) { 
        if (this[j] == arguments[0]) { 
          return true;
      return false;     
    
  3. inArray(comparer)
    Array.prototype.inArray = function(comparer) { 
        for(var i=0; i < this.length; i++) { 
            if(comparer(this[i])) return true; 
        return false; 
    };
    
  4. inArray(comparer)
    Array.prototype.inArray = function(comparer) { 
        for(var i=0; i < this.length; i++) { 
            if(comparer(this[i])) return true; 
        return false; 
    };
    
  5. inArray(comparer)
    Array.prototype.inArray = function(comparer) { 
        for(var i=0; i < this.length; i++) { 
            if(comparer(this[i])) return true; 
        return false; 
    };
    
  6. inArray(comparer)
    Array.prototype.inArray = function(comparer) { 
        for(var i=0; i < this.length; i++) { 
            if(comparer(this[i])) return true; 
        return false; 
    };
    
  7. inArray(e)
    Array.prototype.inArray = function(e) {
        for (var i in this){
            if (this[i]===e) return true;
        return false;
    
  8. inArray(e)
    Array.prototype.inArray = function(e) {
      var length = this.length;
      for (var i = 0; i < length; i++) {
        if (this[i] == e)
          return true;
      return false;
    };
    
  9. inArray(element)
    Array.prototype.inArray = function (element) {
      for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
          return i;
      return -1;
    };