utils.uts 662 B

12345678910111213141516171819202122
  1. // @ts-nocheck
  2. /**
  3. * 在数组的指定位置插入或更新值。
  4. * 如果指定的索引小于数组的长度,则更新该位置的值。
  5. * 如果指定的索引大于或等于数组的长度,则将值添加到数组的末尾。
  6. *
  7. * @param {number[]} arr - 要操作的数字数组。
  8. * @param {number} index - 要插入或更新值的索引位置。
  9. * @param {number} value - 要插入或更新的值。
  10. */
  11. export function pushAt<T>(arr: T[], index: number, value: T){
  12. // #ifdef APP-ANDROID
  13. if (index < arr.length) {
  14. arr[index] = value;
  15. } else {
  16. arr.push(value);
  17. }
  18. // #endif
  19. // #ifndef APP-ANDROID
  20. arr[index] = value;
  21. // #endif
  22. };