findItem
Creates a find item transformation action.
const Action = v.findItem<TInput>(operation);
Generics
TInputextends ArrayInput
Parameters
operationArrayRequirement<TInput>
Explanation
With findItem you can extract the first item of an array that matches the given operation.
Returns
ActionFindItemAction<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
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/findItem/