Nodejs Array Index indexOfAttr(attr, value)

Here you can find the source of indexOfAttr(attr, value)

Method Source Code

// http://stackoverflow.com/questions/7176908/how-to-get-index-of-object-by-its-property-in-javascript
Array.prototype.indexOfAttr = function (attr, value) {
    for(var i = 0; i < this.length; i += 1) {
        if(this[i][attr] === value) {
            return i;
        }/*w  w  w .j  av a2s.  co  m*/
    }
    return -1;
};

Related

  1. indexOf(value)
    Array.prototype.indexOf = function (value) {  
      for(var i=0; i<this.length; i++) {
        if(this[i] === value) {
          return i;
      return -1;
    
  2. indexOf(value, begin, strict)
    Array.prototype.indexOf = function(value, begin, strict)
      for(var i = +begin || 0; i < this.length; i++)
        if(this[i] === value || strict && this[i] == value)
          return i;
      return -1;
    };
    
  3. indexOf(what, i)
    Array.prototype.indexOf = function(what, i) {
            i = i || 0;
            var L = this.length;
            while (i < L) {
                if(this[i] === what) return i;
                ++i;
            return -1;
        };
    ...
    
  4. index(val)
    Array.prototype.index = function(val) {
      for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == val) return i;
      return null;
    };
    
  5. index(val)
    "use strict";
    Array.prototype.index = function(val) {
      for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == val) return i;
      return null;
    };
    
  6. indexOfByFunction(filter)
    Array.prototype.indexOfByFunction = function (filter) {
        return indexOfByFunction(this, filter);
    };
    
  7. indexOfById(id)
    Array.prototype.indexOfById = function(id){
      var index = -1,
        i = 0,
        l = this.length,
        item;
      for(; l--; i++){
        item = this[i];
        if(parseInt(item.id) === id)
          return i;   
    ...
    
  8. indexOfByKey(aKey)
    Array.prototype.indexOfByKey = function(aKey) {
        for(var i = 0; i < this.length; i++) 
            if(this[i].getKey() === aKey)
                return i;
        return -1;
    };
    
  9. indexOfByProp(obj, property)
    Array.prototype.indexOfByProp = function(obj, property) {
      let result = -1;
      this.forEach(function(currentObj, index) {
        if (currentObj[property] === obj[property]) {
          result = index;
      });
      return result;
    };
    ...