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

mozilla

Revision 356979 of String.prototype.trimLeft()

  • Revision slug: JavaScript/Reference/Global_Objects/String/TrimLeft
  • Revision title: String.trimLeft
  • Revision id: 356979
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment Examples ...etc.

Revision Content

{{Non-standard_header}}

Summary

Removes whitespace from the left end of the string.

Method of String
Implemented in JavaScript 1.8.1
ECMAScript Edition None

Syntax

string.trimLeft()

Parameters

None.

Description

The trimLeft method returns the string stripped of whitespace from its left end. trimLeft does not affect the value of the string itself.

Examples

Example: Using trimLeft

The following example displays the lowercase string "foo  ":

var str = "   foo  ";

alert(str.length); // 8

str = str.trimLeft();
alert(str.length); // 5
document.write( str.trimLeft() );

See also

Revision Source

<div>{{Non-standard_header}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>Removes whitespace from the left end of the string.</p>
<table class="standard-table">
  <thead>
    <tr>
      <th class="header" colspan="2">Method of <a href="/en-US/docs/JavaScript/Reference/Global_Objects/String" title="JavaScript/Reference/Global_Objects/String"><code>String</code></a></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Implemented in</td>
      <td>JavaScript 1.8.1</td>
    </tr>
    <tr>
      <td>ECMAScript Edition</td>
      <td>None</td>
    </tr>
  </tbody>
</table>

<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox"><code><var>string</var>.trimLeft()</code></pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<p>None.</p>

<h2 id="Description" name="Description">Description</h2>
<p>The <code>trimLeft</code> method returns the string stripped of whitespace from its left end. <code>trimLeft</code> does not affect the value of the string itself.</p>

<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example:_Using_toLowerCase" name="Example:_Using_toLowerCase">Example: Using <code>trimLeft</code></h3>
<p>The following example displays the lowercase string "foo&nbsp;&nbsp;":</p>

<pre class="brush:js">
var str = "   foo  ";

alert(str.length); // 8

str = str.trimLeft();
alert(str.length); // 5
document.write( str.trimLeft() );
</pre>

<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/String/trim" title="JavaScript/Reference/Global Objects/String/trim"><code>trim()</code></a></li>
  <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/String/trimRight" title="JavaScript/Reference/Global Objects/String/trimRight"><code>trimRight()</code></a></li>
</ul>
Revert to this revision