JavaScript trim() Method removes white spaces from both sides of the string.
Let's say we have a string with spaces on both sides. We can trim these spaces with trim() method.
var string1 = ' HowToCodeSchool.com ';
var trimmed = string1.trim();
document.getElementById('demo').innerHTML = 'Output: ' + trimmed;
Output: HowToCodeSchool.com
As you can see that spaces are trimmed from both sides.
Video Tutorial
Watch video tutorial on JavaScript trim() Method.