trim method
The trim method removes spaces
from the ends of a string. Most often,
this is necessary when the user enters
any values: he can accidentally stick
extra spaces - and our task is to clear
the entered text from them.
Syntax
string.trim();
Example
Let's remove trailing whitespaces from a string:
let str = ' abcde ';
console.log(str.trim());
The code execution result (the spaces are gone):
'abcde'