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
Syntax
string.trimStart()
Return value
A new string.
Examples
console.log(JSON.stringify(" text ".trimStart()));
Output
"text "
const code = " return x;";
console.log(code.length - code.trimStart().length, "spaces of indentation");
Output
4 spaces of indentation
Version history
| Version | Change |
|---|---|
| JavaScript ES2019 | Added |
In other languages
str.lstrip()· Pythonltrim()· PHP
Related
string.trim()· Remove whitespace (spaces, tabs, line breaks) from both ends of a string.string.trimEnd()· Remove whitespace (spaces, tabs, line breaks) from the end of a string only, leaving the start untouched.- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial