What is trimLeft() Method in JavaScript ?
In JavaScript, the trimLeft()
method is used to remove whitespace characters from the beginning (left side) of a string. It returns a new string with leading whitespace characters removed, without modifying the original string.
Syntax:
string.trimLeft()
string
: The original string from which leading whitespace characters will be removed.
Example: Here, In this example, the trimLeft()
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.trimLeft(); console.log(trimmedStr); // Output: "Hello, World!" |
Output
Hello, World!
Contact Us