Space can be present at any position in a string and, a single solution will not work in every situation.
In this article, I have discussed two ways to:
- Trim the extra space from the beginning or end of a string.
- Remove all extra spacing between words.
trim() function for this purpose. The trim function takes one parameter, the string itself and, it returns a trimmed string.
The syntax looks like below:
var content = " The Quick! "; console.log(content.trim()); //The Quick!
Next, you can read how to remove all extra spacing between words from here in my original blog post