Apply your JS skills to key Mozilla projects as an MDN Fellow! http://mzl.la/MDNFellowship

mozilla

Revision 43451 of String.prototype.trim()

  • Revision slug: JavaScript/Reference/Global_Objects/String/Trim
  • Revision title: Trim
  • Revision id: 43451
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment 1 words added

Revision Content

{{ js_minversion_header("1.8.1") }}

String.trim() is part of the ECMAScript 5 standard.

Summary

Removes whitespace from both ends of the string.

Method of String
Implemented in: JavaScript 1.8.1

Syntax

trim()

Parameters

None.

Description

The trim method returns the string stripped of whitespace from both ends. trim does not affect the value of the string itself.

Examples

Example: Using trim

The following example displays the lowercase string "foo":

var orig="   foo  "
document.write(orig.trim())

See Also

{{ languages( { "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/String/Trim"} ) }}

Revision Source

<p>{{ js_minversion_header("1.8.1") }}</p>
<p><code>String.trim()</code> is part of the ECMAScript 5 standard.</p>
<h3 name="Summary">Summary</h3>
<p>Removes whitespace from both ends of the string.</p>
<table class="fullwidth-table"> <tbody> <tr> <td class="header" colspan="2">Method of <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/String" title="en/Core_JavaScript_1.5_Reference/Global_Objects/String">String</a></td> </tr> <tr> <td>Implemented in:</td> <td>JavaScript 1.8.1</td> </tr> </tbody>
</table>
<h3 name="Syntax">Syntax</h3>
<p><code> trim() </code></p>
<h3 name="Parameters">Parameters</h3>
<p>None.</p>
<h3 name="Description">Description</h3>
<p>The <code>trim</code> method returns the string stripped of whitespace from both ends. <code>trim</code> does not affect the value of the string itself.</p>
<h3 name="Examples">Examples</h3>
<h4 name="Example:_Using_toLowerCase">Example: Using <code>trim</code></h4>
<p>The following example displays the lowercase string "foo":</p>
<pre>var orig="   foo  "
document.write(orig.trim())
</pre>
<h3 name="See_Also">See Also</h3>
<ul> <li><a class="internal" href="/En/Core_JavaScript_1.5_Reference/Global_Objects/String/TrimLeft" title="en/Core JavaScript 1.5 Reference/Global Objects/String/trimLeft"><code>trimLeft()</code></a> </li> <li><a class="internal" href="/En/Core_JavaScript_1.5_Reference/Global_Objects/String/TrimRight" title="en/Core JavaScript 1.5 Reference/Global Objects/String/trimRight"><code>trimRight()</code></a></li>
</ul>
<p>{{ languages( { "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/String/Trim"} ) }}</p>
Revert to this revision