Skip to main content
Version: 3.13.0

String.prototype.trimStart()

The trimStart() method removes whitespace from the beginning of a string and returns a new string, without modifying the original string. trimLeft() is an alias of this method.

Syntax

trimStart()

trimLeft()

Return value

A new string representing str stripped of whitespace from its beginning (left side). Whitespace is defined as white space characters plus line terminators.

If the beginning of str has no whitespace, a new string is still returned (essentially a copy of str).

Aliasing

After String.prototype.trim() was standardized, engines also implemented the non-standard method trimLeft. However, for consistency with String.prototype.padEnd(), when the method got standardized, its name was chosen as trimStart. For web compatibility reasons, trimLeft remains as an alias to trimStart, and they refer to the exact same function object. In some engines this means:

String.prototype.trimLeft.name === "trimStart";