> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/text-strings/.truncate.md).

# .truncate()

Truncates a string to a specified maximum length and appends an ellipsis if the string is longer than the maximum length.

`truncate()`

* Receives the maximum length of the truncated string. Default is 200.
* Returns the truncated string with an ellipsis if the original string was longer than the maximum length.

{% code overflow="wrap" lineNumbers="true" %}

```javascript
const originalString = 'This is a very long string that needs to be truncated';
const truncatedString = originalString.truncate(30);
console.log(truncatedString); // Outputs: 'This is a very long string tha...'
```

{% endcode %}

### Use cases

Use `.truncate()` to create compact previews from longer text.

### More examples

Render an article preview:

```javascript
const preview = article.body.truncate(140);

$('#article-preview').text(preview);
```
