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.

Description: Removes whitespace from the beginning and end of the string.

Example: ' chocolate chip cookies ' => 'chocolate chip cookies'

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

Related functions

© 2026 Heifara Buval