transformation

String.prototype.trimStart

Returns a new string with leading whitespace removed. Added in ES2019 (aliased as trimLeft for legacy code).

str.trimStart()

Parameters

Parameter Purpose
(no arguments) Method takes no parameters
returns New string with leading whitespace stripped

Examples

console.log('   hello   '.trimStart());

Prints 'hello '

console.log('\t\n abc'.trimStart());

Prints 'abc'

console.log('abc   '.trimStart());

Prints 'abc '

console.log('   '.trimStart());

Prints '' (all whitespace removed)

Gotcha

trimLeft is a legacy alias — prefer trimStart. Only affects the beginning; trailing whitespace is preserved.

Related methods

← All JS string methods · JS array methods