JavaScript String trimStart()

Example

let text1 = "     Hello World!     ";
let text2 = text1.trimStart();
Try it Yourself »

Description

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

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

The trimStart() method works like trim(), but removes whitespace only from the start of a string.

Note

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

See Also:

The trim() Method

The trimEnd() Method

The padEnd() Method

The padStart() Method


Syntax

string.trimStart()

Parameters

NONE

Return Value

Type Description
A stringA string with removed whitespace from the beginning of the string.



JavaScript String trimStart() is supported in all browsers since January 2020:

Chrome 66 Edge 79 Firefox 61 Safari 12 Opera 50
Apr 2018 Jan 2020 Jun 2018 Sep 2018 May 2018

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.