Skip to content

useArrayFind

Category
Export Size
137 B
Last Changed
2 months ago

Reactive Array.find.

Usage

ts
import { 
useArrayFind
} from '@vueuse/core'
const
list
= [
ref
(1),
ref
(-1),
ref
(2)]
const
positive
=
useArrayFind
(
list
,
val
=>
val
> 0)
// positive.value: 1

Use with reactive array

ts
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

Type Declarations

ts
export type 
UseArrayFindReturn
<
T
= any> =
ComputedRef
<
T
| undefined>
/** * Reactive `Array.find` * * @see https://vueuse.org/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. * * @__NO_SIDE_EFFECTS__ */ export declare function
useArrayFind
<
T
>(
list
:
MaybeRefOrGetter
<
MaybeRefOrGetter
<
T
>[]>,
fn
: (
element
:
T
,
index
: number,
array
:
MaybeRefOrGetter
<
T
>[]) => boolean,
):
UseArrayFindReturn
<
T
>

Source

SourceDocs

Contributors

Anthony Fu
Anthony Fu
SerKo
Michael Cozzolino
Robin
IlyaL
vaakian X
Levi (Nguyễn Lương Huy)
XLor

Changelog

v13.6.0 on
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
v13.2.0 on
43903 - fix(UseArrayFindReturn): Missing template type (#4715)
v13.1.0 on
c1d6e - feat(shared): ensure return types exists (#4659)
v12.8.0 on
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
v12.3.0 on
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)

Released under the MIT License.

Turn AI into a coding partner
Claim 40% off for AIDD Masterclass.
Get discount