String.prototype.trimStart()

Returns a new string with whitespace removed from the beginning.

Since ES2019 Spec ↗

Syntax

str.trimStart()

Returns

string — A new string with leading whitespace removed.

Examples

console.log('  hello  '.trimStart() + '|');
Output
hello  |
console.log('\n\t x'.trimStart());
Output
x

Notes

Only trims the start; trailing whitespace is preserved. `trimLeft` is a legacy alias. Does not mutate the original string.

Browser & runtime support

EnvironmentSince version
chrome 66
firefox 61
safari 12
edge 79
node 10

See also