The trimStart() method in JavaScript is used to remove whitespace characters from the beginning (left side) of a string.
Syntax: string.trimStart()
- string: The string we want to remove whitespace characters from the beginning of.
Example:
let str = " Hello, World! ";
let trimmedStr = str.trimStart();
console.log(trimmedStr); // Output: "Hello, World! "
Explanation:
- We have a string str containing leading and trailing whitespace characters.
- We use trimStart() to remove leading whitespace characters.
- The resulting string, "Hello, World! ", is stored in the variable trimmedStr and logged to the console.
Code Compiler Link: https://app.singhteekam.in/codecompiler/