There are a lot of options for regular expressions you could use to accomplish this. One example that will perform well is:
str.replace( /\s\s+/g, ' ' )
See this question for a full discussion on this exact problem: Regex to replace multiple spaces with a single space