Hello Friends 👋,
Welcome to Infinitbility.
Every time, when we take details from users they’re a lot of chances we will not get the same like we are expecting and
space or white space is one of them.
Today, we will see how we can remove white space at the start and end of the string.
Before going to the solution, let discuss the solution that will help you on which conditions.
The first case, the string has both ( left and right ) side useless spaces.
' Hello World '=>
The second case, the string has only useless space on the left side.
' Hello World'=>
The third case, the string has only useless space on the right side.
'Hello World '=>
The below solution will help you in all the above cases and it will not affect your important or original string like
Now, move to a solution.
trim() method to remove space from the beginning and end of the string.
Let understand with an example.
1let exampleString = " Hello world ";23console.log("exampleString => ", exampleString);45exampleString.trim();
Thanks for reading…
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.