Nodejs Array Index indexOfByProp(obj, property)

Here you can find the source of indexOfByProp(obj, property)

Method Source Code

Array.prototype.indexOfByProp = function(obj, property) {
  let result = -1;/*from w w  w .ja v a2s . c  o  m*/
  // console.log(this);
  this.forEach(function(currentObj, index) {
    if (currentObj[property] === obj[property]) {
      result = index;
    }
  });
  return result;
};

Related

  1. 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;
    };
    
  2. indexOfAttr(attr, value)
    Array.prototype.indexOfAttr = function (attr, value) {
        for(var i = 0; i < this.length; i += 1) {
            if(this[i][attr] === value) {
                return i;
        return -1;
    };
    
  3. indexOfByFunction(filter)
    Array.prototype.indexOfByFunction = function (filter) {
        return indexOfByFunction(this, filter);
    };
    
  4. 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;   
    ...
    
  5. indexOfByKey(aKey)
    Array.prototype.indexOfByKey = function(aKey) {
        for(var i = 0; i < this.length; i++) 
            if(this[i].getKey() === aKey)
                return i;
        return -1;
    };
    
  6. indexOfContent(searchTerm)
    Array.prototype.indexOfContent = function (searchTerm) {
      let index = -1;
      for (var i = 0, len = this.length; i < len; i++) {
        if (this[i].content == searchTerm) {
          index = i;
          break;
      return index
    ...
    
  7. indexOfElement(search, func)
    Array.prototype.indexOfElement = function(search, func) {
      for(var i = 0; i < this.length; i++) {
        var result = func(search, this[i]);
        if(result)
           return i;
      return -1;
    
  8. indexOfGreatestLessThan(val)
    Array.prototype.indexOfGreatestLessThan = function(val) {
      var minIndex = 0;  
      var minDist = Number.MAX_VALUE;
      for (var i = 0; i < this.length; i++) {
        if ((this[i] <= val) && (Math.abs(this[i] - val) < minDist)) {
          minDist = Math.abs(this[i] - val);
          minIndex = i;
      return minIndex;
    
  9. indexOfKey(key)
    Array.prototype.indexOfKey = function(key){
      for(var i in this) if(i == key) return i;
      return -1;