JavaScript (ES2026) reference · String Methods

JavaScript String trimStart() Method

Remove whitespace (spaces, tabs, line breaks) from the start of a string only, leaving the end untouched.

JavaScript (ES2026) Since ES2019

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.trimStart()

Return value

A new string.

Examples

Trim the startTry it yourself
console.log(JSON.stringify("  text  ".trimStart()));

Output

"text  "
Measure indentationTry it yourself
const code = "    return x;";
console.log(code.length - code.trimStart().length, "spaces of indentation");

Output

4 spaces of indentation

Version history

VersionChange
JavaScript ES2019Added

In other languages

Was this page helpful?