Nodejs Array Index indexOfById(id)

Here you can find the source of indexOfById(id)

Method Source Code

Array.prototype.indexOfById = function(id){
   //from  w  w w .jav a  2s.  c  o m
   var index = -1,
      i = 0,
      l = this.length,
      item;
   
   for(; l--; i++){
      item = this[i];
      
      if(parseInt(item.id) === id)
         return i;    
   }
   
   return index;
};

Related

  1. 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;
        };
    ...
    
  2. 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;
    };
    
  3. 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;
    };
    
  4. 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;
    };
    
  5. indexOfByFunction(filter)
    Array.prototype.indexOfByFunction = function (filter) {
        return indexOfByFunction(this, filter);
    };
    
  6. indexOfByKey(aKey)
    Array.prototype.indexOfByKey = function(aKey) {
        for(var i = 0; i < this.length; i++) 
            if(this[i].getKey() === aKey)
                return i;
        return -1;
    };
    
  7. 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;
    };
    ...
    
  8. 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
    ...
    
  9. 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;