Trimming input values of form

While validating form inputs, you must have encountered a situation where we must have got input values with a lot of spaces.
Like this ⬇
console.log(username)
>' ' // -> lot of spaces
Or maybe like this ⬇

But hold on 🔴
Take a cup of coffee ☕
Let’s together see different methods that our dear JavaScript provides to stop this from happening.
TrimStart and TrimEnd
trimStart() and trimEnd() removes the starting and ending whitespaces respectively created by the user on entering the values.

Let's now use the power of both of the above methods by chaining the methods to solve our problem.

Kudos🎊, we succeeded in doing it.Lets go ahead with other alternatives.
TrimLeft and TrimRight
trimLeft() and trimRight() removes the left and right white spaces respectively.

Chaining both the methods as below solves the problem.

Trim
trim() methods removes the whitespaces from both the ends of the string.

Let’s recall the points :
- trimLeft() and trimStart() removes the whitespaces from the start of the string
- trimRight() and trimEnd() removes the whitespaces from the end of the string
- trim() removes the whitespaces from both the ends of the string.

I hope you find it useful and hope you will use it wherever you find its use.
Thank you ✨✨
Happy Coding !!