replace multiple spaces with single space javascript

JavaScript
string = string.replace(/\s\s+/g, ' ');
Source

Also in JavaScript: