JavaScript String trimStart()

Definition and Usage

trimStart() The method removes spaces from the beginning of the string.

trimStart() The method does not change the original string.

trimStart() The way the method works is trim() Similar, but only removes spaces from the beginning of the string.

Note:trimStart() The method was added to JavaScript in ECMAScript 2019.

See Also:

trim() Method

trimEnd() Method

Example

let text1 = "     Hello World!     ";
let text2 = text1.trimStart();

Try It Yourself

Syntax

string.trimStart()

Parameter

No parameters.

Return Value

Type Description
String A string that removes spaces from the beginning of the string.

Browser Support

Starting from January 2020, all browsers support JavaScript String trimStart():

Chrome Edge Firefox Safari Opera
Chrome 66 Edge 79 Firefox 61 Safari 12 Opera 50
2018 April 2020 January 2018 June September 2018 May 2018

Related Pages

JavaScript String

JavaScript String Methods

JavaScript String Search