Spec-Zone.ru › Valibot

findItem

Creates a find item transformation action.

const Action = v.findItem<TInput>(operation);

Generics

  • TInput extends ArrayInput

Parameters

  • operation ArrayRequirement<TInput>

Explanation

With findItem you can extract the first item of an array that matches the given operation.

Returns

  • Action FindItemAction<TInput>

Examples

The following examples show how findItem can be used.

Find duplicate item

Schema to find the first duplicate item in an array.

const DuplicateItemSchema = v.pipe(
  v.array(v.string()),
  v.findItem((item, index, array) => array.indexOf(item) !== index)
);

Related

The following APIs can be combined with findItem.

Schemas

any, array, custom, instance, tuple, unknown

Methods

pipe

Utils

isOfKind, isOfType

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/findItem/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API