JavaScript Trim Method

The trim() methods in JavaScript removes spaces and other whitespace characters from both ends of a string. It is supported in all modern browsers else you can add the trim() method to the String prototype object.

The \s represent whitespace characters while “\uFEFF” represents the zero-width no-break space.