remove extra space in string javascript

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

Also in JavaScript: