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.

Trim()

Type above to see the result…

Want to go further? Chain Trim with other functions, pipe one output into the next and watch your data transform in the visual Playground.

Related functions

© 2026 Heifara Buval