Back

str.trimLeft()

str.trimLeft()

The trimLeft() method removes whitespace from the left end of a 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

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  '

[ Not part of any standard. Implemented in JavaScript 1.8.1. ]


  Created by Mozilla Contributors, license: CC-BY-SA 2.5