remove whitespace

by Mentaldiarrhoe

HTML

<html>
<body>

<span id="x"> Lorem ipsum       dolor sit amet  </span><br>
<span id="out"></span>
</body>
</html>

JavaScript

let str=document.getElementById("x").innerHTML;
clean(str);
function clean(str){
let o=str.replace(/\s(?=\s)/gm,"")


out.innerHTML=o.trim()
//alert(str)
}