es.array.find-index.js 944 B

123456789101112131415161718192021222324
  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 arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');
  6. var FIND_INDEX = 'findIndex';
  7. var SKIPS_HOLES = true;
  8. var USES_TO_LENGTH = arrayMethodUsesToLength(FIND_INDEX);
  9. // Shouldn't skip holes
  10. if (FIND_INDEX in []) Array(1)[FIND_INDEX](function () { SKIPS_HOLES = false; });
  11. // `Array.prototype.findIndex` method
  12. // https://tc39.github.io/ecma262/#sec-array.prototype.findindex
  13. $({ target: 'Array', proto: true, forced: SKIPS_HOLES || !USES_TO_LENGTH }, {
  14. findIndex: function findIndex(callbackfn /* , that = undefined */) {
  15. return $findIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  16. }
  17. });
  18. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  19. addToUnscopables(FIND_INDEX);