﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head># mapItems

> This document is the Markdown version of [valibot.dev/api/mapItems/](https://valibot.dev/api/mapItems/). For the complete documentation index, see [llms.txt](https://valibot.dev/llms.txt).

Creates a map items transformation action.

```ts
const Action = v.mapItems<TInput, TOutput>(operation);
```

## Generics

- `TInput` `extends ArrayInput`
- `TOutput` `extends any`

## Parameters

- `operation` `(item: TInput[number], index: number, array: TInput) => TOutput`

### Explanation

With `mapItems` you can apply an `operation` to each item in an array to transform it.

## Returns

- `Action` `MapItemsAction<TInput, TOutput>`

## Examples

The following examples show how `mapItems` can be used.

### Mark duplicates

```ts
const MarkedArraySchema = v.pipe(
  v.array(v.string()),
  v.mapItems((item, index, array) => {
    const isDuplicate = array.indexOf(item) !== index;
    return { item, isDuplicate };
  })
);
```

## Related

The following APIs can be combined with `mapItems`.

### Schemas

[`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md)