MCPcopy Create free account
hub / github.com/cn-docs/vueuse / useArrayFind

Function useArrayFind

packages/shared/useArrayFind/index.ts:13–22  ·  view source on GitHub ↗
(
  list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
  fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => boolean,
)

Source from the content-addressed store, hash-verified

11 * @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
12 */
13export function useArrayFind<T>(
14 list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
15 fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => boolean,
16): ComputedRef<T | undefined> {
17 return computed(() =>
18 toValue<T | undefined>(
19 toValue(list)
20 .find((element, index, array) => fn(toValue(element), index, array)),
21 ))
22}

Callers 1

index.test.tsFile · 0.90

Calls 1

fnFunction · 0.85

Tested by

no test coverage detected