Categories
JavaScript Answers

How to trim spaces from start and end of string with JavaScript?

Spread the love

Sometimes, we want to trim spaces from start and end of string with JavaScript.

In this article, we’ll look at how to trim spaces from start and end of string with JavaScript.

How to trim spaces from start and end of string with JavaScript?

To trim spaces from start and end of string with JavaScript, we use the string trim method.

For instance, we write

title = title.trim();

to call title.trim to return a string with the title string’s starting and ending whitespaces trimmed out.

Conclusion

To trim spaces from start and end of string with JavaScript, we use the string trim method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *