String.prototype.trim()

  • Revision slug: JavaScript/Reference/Global_Objects/String/Trim
  • Revision title: Trim
  • Revision id: 43443
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment no wording changes; page display name changed to 'trim'

Revision Content

{{ Non-standard_header() }}

Summary

Removes whitespace from both ends of the string.

Method of String
Implemented in: JavaScript 1.9.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

Revision Source

<p>{{ Non-standard_header() }}</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.9.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/Trim" title="en/Core JavaScript 1.5 Reference/Global Objects/String/trim"><code>trim()</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>
Revert to this revision