Remove space from string in javascript
#javascript
Playing with strings in Javascript is a bit tricky. In this article, I am going to describe how to remove space from any string in Javascript.
Even though Javascript provides many inbuilt string functions, we must always aim for using the optimal one to solve any challenge.
Because JavaScript uses the main UI thread and any redundancy can cause a lag in the UI.
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:
- Remove all extra spacing between words.
- Trim the extra space from the beginning or end of a string.