remove extra space from string javascript without replace code example Example: remove extra space in string javascript newString = string.replace(/\s+/g,' ').trim();