What is trimStart() Method in JavaScript ?
Last Updated :
12 Feb, 2024
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()
string
: The original string from which leading whitespace characters will be removed.
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.
Javascript
const str = " Hello, World!" ;
const trimmedStr = str.trimStart();
console.log(trimmedStr);
|
Share your thoughts in the comments
Please Login to comment...