The trimEnd() method in JavaScript is used to remove whitespace characters from the end (right side) of a string.
Syntax: string.trimEnd()
- string: The string we want to remove whitespace characters from the end of.
Example:
let str = " Hello, World! ";
let trimmedStr = str.trimEnd();
console.log(trimmedStr); // Output: " Hello, World!"
Explanation:
- We have a string str containing leading and trailing whitespace characters.
- We use trimEnd() to remove trailing 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/