# ForEachCallback Function

> Callback function for the forEach function of a collection.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Function
- **Path:** DS Server > Reference > JavaScript API > ForEachCallback Function
- **275 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/foreachcallback/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/foreachcallback/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/foreachcallback/llms-full.txt

---

### Description

Callback function for the [forEach](https://docs.textcontrol.com/ds-server/reference/javascript/collection/foreach-method/llms-full.txt) function of a collection.

### Syntax

```javascript
function(<object> item, <number> index, <number> itemCount)
```

### Examples

The following example demonstrates `ForEachCallback` in a practical document-editing workflow. Callback function for the forEach function of a collection.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

function forEachCallback(item, index, itemCount) {
    console.log("Callback values:", { item, index, itemCount });
}

function useForEachCallback(s) {
    s.forEach(forEachCallback, onTxError);
}
```

---

## Nearby

- **Previous:** [Javascript: FootnoteEventArgs.referenceMarkStart Property](https://docs.textcontrol.com/ds-server/reference/javascript/footnoteeventargs/referencemarkstart-property/llms-full.txt)
- **Next:** [FormattedText Object](https://docs.textcontrol.com/ds-server/reference/javascript/formattedtext/llms-full.txt)
