esnext.array.last-index.js 728 B

12345678910111213141516171819202122
  1. 'use strict';
  2. // TODO: Remove from `core-js@4`
  3. var DESCRIPTORS = require('../internals/descriptors');
  4. var addToUnscopables = require('../internals/add-to-unscopables');
  5. var toObject = require('../internals/to-object');
  6. var lengthOfArrayLike = require('../internals/length-of-array-like');
  7. var defineProperty = require('../internals/object-define-property').f;
  8. // `Array.prototype.lastIndex` getter
  9. // https://github.com/keithamus/proposal-array-last
  10. if (DESCRIPTORS) {
  11. defineProperty(Array.prototype, 'lastIndex', {
  12. configurable: true,
  13. get: function lastIndex() {
  14. var O = toObject(this);
  15. var len = lengthOfArrayLike(O);
  16. return len == 0 ? 0 : len - 1;
  17. }
  18. });
  19. addToUnscopables('lastIndex');
  20. }