es.array.find-index.js 769 B

123456789101112131415161718192021
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var $findIndex = require('../internals/array-iteration').findIndex;
  4. var addToUnscopables = require('../internals/add-to-unscopables');
  5. var FIND_INDEX = 'findIndex';
  6. var SKIPS_HOLES = true;
  7. // Shouldn't skip holes
  8. if (FIND_INDEX in []) Array(1)[FIND_INDEX](function () { SKIPS_HOLES = false; });
  9. // `Array.prototype.findIndex` method
  10. // https://tc39.es/ecma262/#sec-array.prototype.findindex
  11. $({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {
  12. findIndex: function findIndex(callbackfn /* , that = undefined */) {
  13. return $findIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  14. }
  15. });
  16. // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
  17. addToUnscopables(FIND_INDEX);