/
githubmirror
/
ChatGPT-Next-Web
Обзор
Документация
Войти
/
githubmirror
/
ChatGPT-Next-Web
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
app/polyfill.ts
27 строк
623 B
Yidadaa
fix: #397 #373 Array.prototype.at polyfill errors
03 апр 2023, 08:29
03 апр 2023, 08:29
5c75b6c
Код
Авторство
О чём код?
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 {};