If you need to replace multiple spaces (double spaces) in a string to single space with JavaScript you can use next string method:
The replace() method searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring.