@pengzhanbo/utils - v3.4.1
    Preparing search index...

    Function findFirstThen

    • Find the first element in the array that satisfies the provided testing function and execute the given callback function.

      查找数组中第一个满足提供的测试函数的元素,并执行给定的回调函数。

      Type Parameters

      • T

      Parameters

      • array: T[]

        The array to search in 要搜索的数组

      • predicate: (value: T, index: number, array: T[]) => boolean

        A function to test each element. Return true to indicate a matching element has been found. 用于测试每个元素的函数。返回 true 表示已找到匹配元素。

      • then: (value: T, index: number, array: T[]) => void

        A function to execute on the found element. 找到匹配元素后要执行的函数。

      • start: number = 0

        The index at which to start the search. Defaults to 0. 开始搜索的索引。默认值为 0。

      Returns boolean

      Whether any element satisfies the testing function. 是否有任何元素满足测试函数。

      const arr = [1, 2, 3, 4, 5]
      findFirstThen(arr, (v) => v > 3, (v) => console.log(v)) // 4