You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
743 B
20 lines
743 B
'use strict'; |
|
var $ = require('../internals/export'); |
|
var toObject = require('../internals/to-object'); |
|
var lengthOfArrayLike = require('../internals/length-of-array-like'); |
|
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity'); |
|
var addToUnscopables = require('../internals/add-to-unscopables'); |
|
|
|
// `Array.prototype.at` method |
|
// https://github.com/tc39/proposal-relative-indexing-method |
|
$({ target: 'Array', proto: true }, { |
|
at: function at(index) { |
|
var O = toObject(this); |
|
var len = lengthOfArrayLike(O); |
|
var relativeIndex = toIntegerOrInfinity(index); |
|
var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex; |
|
return (k < 0 || k >= len) ? undefined : O[k]; |
|
} |
|
}); |
|
|
|
addToUnscopables('at');
|
|
|