Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

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

Related recipes

In the tutorial

  • String methods — Useful string methods in JavaScript: finding a position, reading characters, padStart, repeat, split and join, method chains.

Thanks for reading!

Donate to the site — we work hard for you.