useArrayIncludes ​
Reactive Array.includes
Usage ​
Use with reactive array ​
js
import { useArrayIncludes } from '@vueuse/core'
const list = ref([0, 2, 4, 6, 8])
const result = useArrayIncludes(list, 10)
// result.value: false
list.value.push(10)
// result.value: true
list.value.pop()
// result.value: false
Type Declarations ​
Show Type Declarations
typescript
export type UseArrayIncludesComparatorFn<T, V> = (
element: T,
value: V,
index: number,
array: MaybeRefOrGetter<T>[],
) => boolean
export interface UseArrayIncludesOptions<T, V> {
fromIndex?: number
comparator?: UseArrayIncludesComparatorFn<T, V> | keyof T
}
/**
* Reactive `Array.includes`
*
* @see https://vueuse.org/useArrayIncludes
*
* @returns true if the `value` is found in the array. Otherwise, false.
*/
export declare function useArrayIncludes<T, V = any>(
list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
value: MaybeRefOrGetter<V>,
comparator?: UseArrayIncludesComparatorFn<T, V>,
): ComputedRef<boolean>
export declare function useArrayIncludes<T, V = any>(
list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
value: MaybeRefOrGetter<V>,
comparator?: keyof T,
): ComputedRef<boolean>
export declare function useArrayIncludes<T, V = any>(
list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
value: MaybeRefOrGetter<V>,
options?: UseArrayIncludesOptions<T, V>,
): ComputedRef<boolean>
Source ​
Contributors ​
Anthony Fu
丶远方
Changelog ​
v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
0a72b
- feat(toValue): rename resolveUnref
to toValue
v10.0.0-beta.0
on 3/14/2023