# CommentCollection Object

> Contains all comments in the main text or another part of a document. All comments are associated with a certain piece of text of the document. The collection consists of CommentedText objects, describing the position and length of the commented text and the comment string itself. A collection object can be obtained with the FormattedText.comments property.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Object
- **Introduced:** 30.0
- **Path:** DS Server > Reference > JavaScript API > CommentCollection Object
- **934 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/llms-full.txt

---

### Description

Contains all comments in the main text or another part of a document. All comments are associated with a certain piece of text of the document. The collection consists of [CommentedText](https://docs.textcontrol.com/ds-server/reference/javascript/commentedtext/llms-full.txt) objects, describing the position and length of the commented text and the comment string itself. A collection object can be obtained with the [FormattedText.comments](https://docs.textcontrol.com/ds-server/reference/javascript/formattedtext/comments-property/llms-full.txt) property.

### Syntax

```javascript
CommentCollection
```

### Examples

The following example demonstrates `CommentCollection` in a practical document-editing workflow. It contains all comments in the main text or another part of a document. All comments are associated with a certain piece of text of the document. The collection consists of CommentedText objects, describing the position and length of the commented text and the comment string itself. A collection object can be obtained with the FormattedText.comments property.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const comments = mainText.comments;
    comments.getItem(
        function(comment) {
            if (!comment) {
                console.warn("No commented text was returned.");
                return;
            }
            
            console.log("get item result:", comment);
        },
        onTxError
    );
}, onTxError);
```

---

## In This Section

- [Javascript: CommentCollection.add Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/add-method/llms-full.txt): Creates a comment with the specified comment string. The current text selection defines the commented text.
- [Javascript: CommentCollection.addAtPosition Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/addatposition-method/llms-full.txt): Creates a comment with the specified comment string, start position and length.
- [Javascript: CommentCollection.addReply Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/addreply-method/llms-full.txt): Creates a reply to an existing comment using the specified comment string.
- [Javascript: CommentCollection.getItem Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/getitem-method/llms-full.txt): Gets the Comment containing the current text input position from the collection.
- [Javascript: CommentCollection.getNextItem Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/getnextitem-method/llms-full.txt): Gets the next comment in the text flow.
- [Javascript: CommentCollection.getPreviousItem Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/getpreviousitem-method/llms-full.txt): Gets the previous comment in the text flow.
- [Javascript: CommentCollection.remove Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/remove-method/llms-full.txt): Removes a comment from the collection.

---

## Nearby

- **Previous:** [Javascript: CommentCallbackData.comment Property](https://docs.textcontrol.com/ds-server/reference/javascript/commentcallbackdata/comment-property/llms-full.txt)
- **Next:** [Javascript: CommentCollection.add Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/add-method/llms-full.txt)
