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.
let exampleString = " Hello world "; console.log("exampleString => ", exampleString); exampleString.trim();
Thanks for reading…