mozilla

Revision 523949 of String.prototype.trimLeft()

  • Revision slug: Web/JavaScript/Reference/Global_Objects/String/TrimLeft
  • Revision title: String.prototype.trimLeft()
  • Revision id: 523949
  • Created:
  • Creator: rvighne
  • Is current revision? No
  • Comment

Revision Content

{{JSRef("Global_Objects", "String")}} {{Non-standard_header}}

Summary

The trimLeft() removes whitespace from the left end of the string.

Syntax

str.trimLeft()

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  ";

console.log(str.length); // 8

str = str.trimLeft();
console.log(str.length); // 5
console.log(str);        // "foo  "

Specifications

None. Not part of any standard. Implemented in JavaScript 1.8.1.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatGeckoDesktop("1.9.1") }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatVersionUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See also

  • {{jsxref("String.prototype.trim()")}}
  • {{non-standard_inline }} {{jsxref("String.prototype.trimRight()")}}

Revision Source

<div>
 {{JSRef("Global_Objects", "String")}} {{Non-standard_header}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code><strong>trimLeft()</strong></code> removes whitespace from the left end of the string.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<code><var>str</var>.trimLeft()</code></pre>
<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.3A_Using_trimLeft">Example: Using <code>trimLeft</code></h3>
<p>The following example displays the lowercase string "foo&nbsp;&nbsp;":</p>
<pre class="brush:js;highlight:[5]">
var str = "   foo  ";

console.log(str.length); // 8

str = str.trimLeft();
console.log(str.length); // 5
console.log(str);        // "foo  "
</pre>
<h2 id="Specifications">Specifications</h2>
<p>None. Not part of any standard. Implemented in JavaScript 1.8.1.</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatGeckoDesktop("1.9.1") }}</td>
    <td>{{ CompatUnknown() }}</td>
    <td>{{ CompatUnknown() }}</td>
    <td>{{ CompatUnknown() }}</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Chrome for Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{ CompatUnknown() }}</td>
    <td>{{ CompatUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatUnknown() }}</td>
    <td>{{ CompatUnknown() }}</td>
    <td>{{ CompatUnknown() }}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_Also" name="See_Also">See also</h2>
<ul>
 <li>{{jsxref("String.prototype.trim()")}}</li>
 <li>{{non-standard_inline }} {{jsxref("String.prototype.trimRight()")}}</li>
</ul>
Revert to this revision