[Javascript] How can I trim a string?


I want to remove all whitespaces from the beginning and from the end of the string, How can I do that in JavaScript?

1 Answer

3 years ago by

str.trim() method is used to trim all whitespaces from the beginning and from the end of the string.

Check the below example for usage:

let str = "              Hello, World!      ";

console.log(str.trim());

Run here https://onecompiler.com/javascript/3xns6uctu

3 years ago by Meera