Spec-Zone.ru › Valibot

filterItems

Creates a filter items transformation action.

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

Generics

  • TInput extends ArrayInput

Parameters

  • operation ArrayRequirement<TInput>

Explanation

With filterItems you can filter the items of an array. Returning true for an item will keep it in the array and returning false will remove it.

Returns

  • Action FilterItemsAction<TInput>

Examples

The following examples show how filterItems can be used.

Filter duplicate items

Schema to filter duplicate items from an array.

const FilteredArraySchema = v.pipe(
  v.array(v.string()),
  v.filterItems((item, index, array) => array.indexOf(item) === index)
);

Related

The following APIs can be combined with filterItems.

Schemas

any, array, custom, instance, tuple, unknown

Methods

pipe

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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