site:stackoverflow.com javascript replace multiple spaces with single space

JavaScript
var multiSpacesString="I  have     some big    spaces.";
var singleSpacesString=multiSpacesString.replace(/  +/g, ' ');//"I have some big spaces."
Source

Also in JavaScript: