Open In App

What is trimStart() Method in JavaScript ?

In JavaScript, the trimStart() method is used to remove whitespace characters from the beginning of a string. It returns a new string with leading whitespace characters removed, without modifying the original string.

Syntax:

string.trimStart()

Example: Here, the trimStart() method is called on the str string to remove leading whitespace characters from the beginning of the string. The resulting string, "Hello, World!", is assigned to the variable trimmedStr. Note that the original string str remains unchanged.




const str = "   Hello, World!";
const trimmedStr = str.trimStart();
 
console.log(trimmedStr); // Output: "Hello, World!"

Output
Hello, World!
Article Tags :