Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useArrayFind.md
1---2category: Array3---45# useArrayFind67Reactive `Array.find`.89## Usage1011```ts12import { useArrayFind } from '@vueuse/core'1314const list = [ref(1), ref(-1), ref(2)]15const positive = useArrayFind(list, val => val > 0)16// positive.value: 117```1819### Use with reactive array2021```ts22import { useArrayFind } from '@vueuse/core'2324const list = reactive([-1, -2])25const positive = useArrayFind(list, val => val > 0)26// positive.value: undefined27list.push(1)28// positive.value: 129```3031## Type Declarations3233```ts34export type UseArrayFindReturn<T = any> = ComputedRef<T | undefined>35/**36* Reactive `Array.find`37*38* @see https://vueuse.org/useArrayFind39* @param list - the array was called upon.40* @param fn - a function to test each element.41*42* @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.43*44* @__NO_SIDE_EFFECTS__45*/46export declare function useArrayFind<T>(47list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,48fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => boolean,49): UseArrayFindReturn<T>50```51