How to remove spaces from a string in javascript
anjan-dutta
Posted on May 25, 2021
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 the extra space from the beginning or end of a string.
Javascript has an inbuild 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!
Simple, right!
Next, you can read how to remove all extra spacing between words from here in my original blog post
💖 💪 🙅 🚩
anjan-dutta
Posted on May 25, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.