Nodejs Array Find by Index findIndex(obj)

Here you can find the source of findIndex(obj)

Method Source Code

Array.prototype.findIndex = function (obj) {
  for (var i = 0, imax = this.length; i < imax; i++) {
    var ectypeObj = this[i];
    var ectypeObjLength = 0, successLength = 0;
    for (var k in ectypeObj) {
      ectypeObjLength += 1;/* w w  w. j  a v a2  s.  c o m*/
      if (ectypeObj[k] === obj[k]) {
        successLength += 1;
      }
    }
    if (ectypeObjLength === successLength) {
      return i;
    }
  }
  return -1;
}

Related

  1. findIndex(callback)
    'use strict';
    Array.prototype.findIndex = Array.prototype.findIndex || function(callback) {
      if (this === null) {
        throw new TypeError('Array.prototype.findIndex called on null or undefined');
      } else if (typeof callback !== 'function') {
        throw new TypeError('callback must be a function');
      var list = Object(this);
      var length = list.length >>> 0;
    ...
    
  2. findIndex(fn, v)
    Array.prototype.findIndex = function(fn, v) {
        var isFN = typeof(fn) === 'function';
        var isV = v !== undefined;
        for (var i = 0, len = this.length; i < len; i++) {
            if (isFN) {
                if (fn(this[i], i)) {
                    return i;
                continue;
    ...