Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

Commit 3f3f179

Browse files
committed
Add Array.prototype.at polyfill
1 parent 71ab75b commit 3f3f179

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

assets/polyfills.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

5-
const hasOwn = function hasOwn(o, p) {
5+
Object.hasOwn = function (o, p) {
66
const obj = Object(o);
77
const key = String(p);
88
return Object.prototype.hasOwnProperty.call(obj, key);
99
}
1010

11-
Object.hasOwn = hasOwn;
11+
Array.prototype.at = function (index) {
12+
if (index >= 0) {
13+
return this[index];
14+
} else {
15+
return this[this.length + index];
16+
}
17+
};

0 commit comments

Comments
 (0)