R
fn

useArrayIncludes

v0.0.15testeddemo

Reactive `Array.prototype.includes` with an optional comparator and `fromIndex`. The source array and its items may be reactive.

Examples

ts
const list = ref([1, 2, 3, 4]);
const hasThree = useArrayIncludes(list, 3); // true
ts
const list = ref([{ id: 1 }, { id: 2 }]);
const hasTwo = useArrayIncludes(list, 2, 'id'); // compare by key
ts
const list = ref(['a', 'b', 'a']);
const fromSecond = useArrayIncludes(list, 'a', { fromIndex: 1 }); // true

Demo

Loading demo…

Signatures

ts
export function useArrayIncludes<T, V = T>(
  list: MaybeRefOrGetter<Array<MaybeRefOrGetter<T>>>,
  value: MaybeRefOrGetter<V>,
  comparator?: UseArrayIncludesComparatorFn<T, V>,
): UseArrayIncludesReturn;
ts
export function useArrayIncludes<T, V = T>(
  list: MaybeRefOrGetter<Array<MaybeRefOrGetter<T>>>,
  value: MaybeRefOrGetter<V>,
  comparator?: keyof T,
): UseArrayIncludesReturn;
ts
export function useArrayIncludes<T, V = T>(
  list: MaybeRefOrGetter<Array<MaybeRefOrGetter<T>>>,
  value: MaybeRefOrGetter<V>,
  options?: UseArrayIncludesOptions<T, V>,
): UseArrayIncludesReturn;

Type Parameters

T
V= T

Parameters

ParameterTypeDescription
listMaybeRefOrGetter<MaybeRefOrGetter<T>[]>The source array (items can be reactive)
valueMaybeRefOrGetter<V>The value to search for (may be reactive)
comparator?UseArrayIncludesComparatorFn<T, V> | keyof T | UseArrayIncludesOptions<T, V> | undefinedA comparator function, a key of `T` to compare by, or an options object with `comparator`/`fromIndex`

Returns

UseArrayIncludesReturnA computed boolean that is `true` when the value is found