Files
2026-01-16 00:12:33 +08:00

23 lines
571 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// @/uni_modules/lime-shared/arrayUtils.ts
/**
* 兼容版 findLastIndexES2023 polyfill
*/
export function findLastIndex<T>(
array : T[],
predicate : (value : T, index : number, obj : T[]) => boolean) : number {
// #ifndef UNI-APP-X && APP-ANDROID
if (typeof array.findLastIndex == 'function') {
// 如果原生支持,直接用(未来兼容)
return array.findLastIndex(predicate);
}
// #endif
// 否则降级到 for 循环
for (let i = array.length - 1; i >= 0; i--) {
if (predicate(array[i], i, array)) {
return i;
}
}
return -1;
}