Standard built-ins

String.prototype.trim()

Try the free JavaScript compiler

Removes ECMAScript whitespace and line terminators at both edges without collapsing interior whitespace.

Formal Syntax & Structure

javascript syntaxjavascript
text.trim()

Return Value

String

Trimmed text.

Working Example

Example Snippetjavascript
console.log(JSON.stringify(" a ".trim()));
JavaScript Reference