JSFiddle - React, Tailwind, and code Playground

JavaScript

var str = '    Hello   ';
var trim = str.replace(/^\s+|\s+$/g, '');
console.log(trim);