JavaScript Trim
trim() removes whitespace (spaces, tabs, line breaks) from both ends of a string and returns the cleaned copy. Whitespace inside the string is preserved.
Syntax
str.trim() Examples
| Input | Arguments | Output |
|---|---|---|
| " hi " | — | "hi" |
When to use it
- Clean form inputs before validation or storage.
Try it live
Type your input and see Trim transform it instantly.
Want to go further? Chain Trim with other functions in the visual Playground — pipe one output into the next and watch your data transform.