String.prototype.trimStart
Removes whitespace and line breaks from the start of a string.
Available since: ES2019
Syntax
str.trimStart()Return value
stringA new string without leading whitespace.
Examples
Trailing spaces stay:
console.log(`[${' Anna '.trimStart()}]`);Output:
[Anna ]Notes
To remove whitespace from both ends use trim().
See also
- String.prototype.trim — Removes whitespace from both ends of a string.
- String.prototype.trimEnd — Removes whitespace and line breaks from the end of a string.
Related recipes
In the tutorial
- String methods — Useful string methods in JavaScript: finding a position, reading characters, padStart, repeat, split and join, method chains.