Skip to tool

JavaScript String.trim() Online

Trim whitespace from both ends, with an optional custom character set.

The output updates as you type. The tool processes input in your browser.

Worked example

A custom trim set removes the listed characters from the boundaries while preserving them inside the string.

Chars to trim (optional)
""
Sample input
   manuals plus   
Sample output
manuals plus

Using this operation in JavaScript

The interactive result uses JavaScript. JavaScript string indexes count UTF-16 code units. Use code-point iteration when working with supplementary Unicode characters.

JavaScript reference