mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-07 03:45:33 +08:00
27
app/polyfill.ts
Normal file
27
app/polyfill.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
declare global {
|
||||
interface Array<T> {
|
||||
at(index: number): T | undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Array.prototype.at) {
|
||||
Array.prototype.at = function (index: number) {
|
||||
// Get the length of the array
|
||||
const length = this.length;
|
||||
|
||||
// Convert negative index to a positive index
|
||||
if (index < 0) {
|
||||
index = length + index;
|
||||
}
|
||||
|
||||
// Return undefined if the index is out of range
|
||||
if (index < 0 || index >= length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Use Array.prototype.slice method to get value at the specified index
|
||||
return Array.prototype.slice.call(this, index, index + 1)[0];
|
||||
};
|
||||
}
|
||||
|
||||
export {};
|
Reference in New Issue
Block a user