In JavaScript/jQuery, what is the best/fastest way to transform two or more spaces in only one space in any string of an input field?
Possibly without regex, please.
<script>
function spaces() {
var textInput = insertText.value;
while (textInput.includes(" ")) {
var textInput = (textInput.replace(" ", " "));
}
alert(textInput);
}
</script>
<input type="text" id="insertText" value="word1 word2">
<button onclick="spaces()">ok</button>