Skip to content

trim

The trim() method removes whitespace from the start and end of a string. Whitespace includes spaces, tabs, line breaks, and other Unicode whitespace characters.

Interactive example

Syntax

typescript
function trim<
	GenericInput extends string
>(input: GenericInput): string

Parameters

  • input: The string from which to remove leading and trailing whitespace.

Return value

A new string representing the calling string without leading and trailing whitespace.

See also

  • trimStart - Removes whitespace at the start only
  • trimEnd - Removes whitespace at the end only

Sources

Released under the MIT license.