JavaScript: Whitespace Characters

By Xah Lee. Date: . Last updated: .

The following methods trim whitespace.

Whitespace is defined to be the following:

U+0009
CHARACTER TABULATION ("\t")
U+000A
LINE FEED ("\n")
U+000B
LINE TABULATION
U+000C
FORM FEED ("\f")
U+000D
CARRIAGE RETURN ("\r")
U+0020
SPACE
U+00A0
NO-BREAK SPACE
U+2028
LINE SEPARATOR
U+2029
PARAGRAPH SEPARATOR
U+FEFF
ZERO WIDTH NO-BREAK SPACE
Other category “Zs”
Any other Unicode “Separator, space” codepoint
JS in Depth
XAH  BUY NOW