JSFiddle - React, Tailwind, and code Playground

JavaScript

var str = "BOBBY                LEE              "; // x[i]
str = str.replace(/\s+/g, ' '); // Keep only one space character
str = str.trim();

alert(str +".");