String trimStart()
String trimStart() method is used to remove whitespace from the beginning of a string.
The following characters are the whitespace characters:
- A space character
- A tab character
- A carriage return character
- A new line character
- A vertical tab character
- A form feed character
Syntax
string.trimStart()
Parameters
None
Return value
Returns a new string with removed whitespace from the beginning of the string.
Visual Representation
Example: How to Use String trimStart() Method
let text = ' Hello Messi ';
console.log(text);
console.log(text.trimStart());
Output
Hello Messi
Hello Messi
String trimEnd()
String trimEnd() method is used to remove whitespace from the end of a string and returns a new string, without modifying the original string.
Syntax
string.trimEnd()
Parameters
None.
Return value
It returns a new string with removed whitespace from the end of the string.
Visual Representation
Example: How to Use String trimEnd() Method
let text1 = ' Hello Messi ';
console.log(text1);
console.log(text1.trimEnd());
Output
Hello Messi
Hello Messi
Browser compatibility
The browsers supported by both methods are listed below:
- Google Chrome 66
- Firefox 61
- Edge 79
- Safari 12
- Opera 53
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.