es.array.index-of.js 970 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. /* eslint-disable es-x/no-array-prototype-indexof -- required for testing */
  3. var $ = require('../internals/export');
  4. var uncurryThis = require('../internals/function-uncurry-this');
  5. var $IndexOf = require('../internals/array-includes').indexOf;
  6. var arrayMethodIsStrict = require('../internals/array-method-is-strict');
  7. var un$IndexOf = uncurryThis([].indexOf);
  8. var NEGATIVE_ZERO = !!un$IndexOf && 1 / un$IndexOf([1], 1, -0) < 0;
  9. var STRICT_METHOD = arrayMethodIsStrict('indexOf');
  10. // `Array.prototype.indexOf` method
  11. // https://tc39.es/ecma262/#sec-array.prototype.indexof
  12. $({ target: 'Array', proto: true, forced: NEGATIVE_ZERO || !STRICT_METHOD }, {
  13. indexOf: function indexOf(searchElement /* , fromIndex = 0 */) {
  14. var fromIndex = arguments.length > 1 ? arguments[1] : undefined;
  15. return NEGATIVE_ZERO
  16. // convert -0 to +0
  17. ? un$IndexOf(this, searchElement, fromIndex) || 0
  18. : $IndexOf(this, searchElement, fromIndex);
  19. }
  20. });