es.array.index-of.js 973 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var $indexOf = require('../internals/array-includes').indexOf;
  4. var arrayMethodIsStrict = require('../internals/array-method-is-strict');
  5. var arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');
  6. var nativeIndexOf = [].indexOf;
  7. var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [1].indexOf(1, -0) < 0;
  8. var STRICT_METHOD = arrayMethodIsStrict('indexOf');
  9. var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', { ACCESSORS: true, 1: 0 });
  10. // `Array.prototype.indexOf` method
  11. // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
  12. $({ target: 'Array', proto: true, forced: NEGATIVE_ZERO || !STRICT_METHOD || !USES_TO_LENGTH }, {
  13. indexOf: function indexOf(searchElement /* , fromIndex = 0 */) {
  14. return NEGATIVE_ZERO
  15. // convert -0 to +0
  16. ? nativeIndexOf.apply(this, arguments) || 0
  17. : $indexOf(this, searchElement, arguments.length > 1 ? arguments[1] : undefined);
  18. }
  19. });