Sometimes, we want to remove strings in beginning and end with JavaScript.
In this article, we’ll look at how to remove strings in beginning and end with JavaScript.
How to remove strings in beginning and end with JavaScript?
To remove strings in beginning and end with JavaScript, we can use the string trim method.
For instance, we write:
const s = ' foo '
const trimmed = s.trim()
console.log(trimmed)
to call s.trim to return a string without the whitespaces at the beginning and the end of s.
Therefore, trimmed is 'foo'.
Conclusion
To remove strings in beginning and end with JavaScript, we can use the string trim method.