6 out of 9 rated this helpful - Rate this topic

trim Method (String) (JavaScript)

JavaScript - Internet Explorer 10

Removes the leading and trailing white space and line terminator characters from a string.

stringObj.trim()
stringObj

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

The original 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 comprehensive list of white space and line terminator characters.

For an example that shows how to implement your own trim method, see Prototypes and Prototype Inheritance.

The following example illustrates the use of the trim method.

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

document.write("[" + message.trim() + "]");
document.write("<br/>");
document.write("length: " + message.trim().length);

// Output:
//  [abc def]
//  length: 7

Supported in the following document modes: Internet Explorer 9 standards and Internet Explorer 10 standards. Also supported in Windows Store apps. 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)
© 2013 Microsoft. All rights reserved.