Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
689 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var toObject = require('../internals/to-object');
|
---|
4 | var toLength = require('../internals/to-length');
|
---|
5 | var toInteger = require('../internals/to-integer');
|
---|
6 | var addToUnscopables = require('../internals/add-to-unscopables');
|
---|
7 |
|
---|
8 | // `Array.prototype.at` method
|
---|
9 | // https://github.com/tc39/proposal-relative-indexing-method
|
---|
10 | $({ target: 'Array', proto: true }, {
|
---|
11 | at: function at(index) {
|
---|
12 | var O = toObject(this);
|
---|
13 | var len = toLength(O.length);
|
---|
14 | var relativeIndex = toInteger(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.