Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

trim Method (JavaScript)

Returns a string with leading and trailing white space and line terminator characters removed.

stringObj.trim()
stringObj

Required. A String object or string literal. This string is not modified by the trim method.

A string with leading and trailing white space and line terminator characters removed.

The characters that are removed include space, tab, form feed, carriage return, and line feed. See Special Characters (JavaScript) for a more comprehensive list of white space and line terminator characters.

The following example illustrates the use of the trim method.

var message = "    abc def     \r\n  ";

alert("'" + message.trim() + "'");
alert("length: " + message.trim().length);

// Output:
//  'abc def'
//  length: 7

Supported in the Internet Explorer 9 standards document mode. See Version Information.

Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.