Here you can find the source of 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; }//from w w w. j a va 2s .c o m continue; } if (isV) { if (this[i] && this[i][fn] === v) { return i; } continue; } if (this[i] === fn) { return i; } } return -1; };
'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; ...
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; if (ectypeObj[k] === obj[k]) { successLength += 1; if (ectypeObjLength === successLength) { return i; return -1;