main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
733 bytes
|
Rev | Line | |
---|
[79a0317] | 1 | 'use strict';
|
---|
| 2 | var $ = require('../internals/export');
|
---|
| 3 | var toObject = require('../internals/to-object');
|
---|
| 4 | var lengthOfArrayLike = require('../internals/length-of-array-like');
|
---|
| 5 | var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
---|
| 6 | var addToUnscopables = require('../internals/add-to-unscopables');
|
---|
| 7 |
|
---|
| 8 | // `Array.prototype.at` method
|
---|
| 9 | // https://tc39.es/ecma262/#sec-array.prototype.at
|
---|
| 10 | $({ target: 'Array', proto: true }, {
|
---|
| 11 | at: function at(index) {
|
---|
| 12 | var O = toObject(this);
|
---|
| 13 | var len = lengthOfArrayLike(O);
|
---|
| 14 | var relativeIndex = toIntegerOrInfinity(index);
|
---|
| 15 | var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
|
---|
| 16 | return (k < 0 || k >= len) ? undefined : O[k];
|
---|
| 17 | }
|
---|
| 18 | });
|
---|
| 19 |
|
---|
| 20 | addToUnscopables('at');
|
---|
Note:
See
TracBrowser
for help on using the repository browser.