useArrayFind
响应式的 Array.find
。
用法
js
import { useArrayFind } from '@vueuse/core'
const list = [ref(1), ref(-1), ref(2)]
const positive = useArrayFind(list, val => val > 0)
// positive.value: 1
与响应式数组一起使用
js
import { useArrayFind } from '@vueuse/core'
const list = reactive([-1, -2])
const positive = useArrayFind(list, val => val > 0)
// positive.value: undefined
list.push(1)
// positive.value: 1
类型声明
typescript
/**
* Reactive `Array.find`
*
* @see https://vueuse.org.cn/useArrayFind
* @param list - the array was called upon.
* @param fn - a function to test each element.
*
* @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
*/
export declare function useArrayFind<T>(
list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => boolean,
): ComputedRef<T | undefined>
源码
贡献者
更新日志
v12.8.0
于 2025/3/5v12.3.0
于 2025/1/259f75
- feat(toValue): 弃用来自 @vueuse/shared
的 toValue
,转而使用 Vue 原生类型v12.0.0-beta.1
于 2024/11/21v10.0.0-beta.4
于 2023/4/134d757
- feat(types)!: 将 MaybeComputedRef
重命名为 MaybeRefOrGetter
0a72b
- feat(toValue): 将 resolveUnref
重命名为 toValue