---
title: "forEach command"
description: "Use the forEach command in Tiptap to loop through an array of items and insert content into the editor. Learn more in our docs!"
canonical_url: "https://tiptap.dev/docs/editor/api/commands/for-each"
---

# forEach command

Use the forEach command in Tiptap to loop through an array of items and insert content into the editor. Learn more in our docs!

Loop through an array of items.

## Parameters

`items: any[]`

An array of items.

`fn: (item: any, props: CommandProps & { index: number }) => boolean`

A function to do anything with your item.

## Use the forEach command

```js
const items = ['foo', 'bar', 'baz']

editor.commands.forEach(items, (item, { commands }) => {
  return commands.insertContent(item)
})
```
