Home / Javascript Tips Generated By ChatGPT / Using String.trim to Remove Whitespace in Javascript Remove whitespace from both ends of a string. Source Code let text = ' Hello, world! '; console.log(text.trim());