How can I remove all extra space between words in a string literal?
\"some value\"
Should become
\"some value\"
<
In case we want to avoid the replace function with regex,
We can achieve same result by
str.split(' ').filter(s => s).join(' ')
// var str = " This should become something else too . ";
// result is "This should become something else too ."
First, split the original string with space, then we will have empty string and words in an array. Second, filter to remain only words, then join all words with a whitespace.