js how to delete extra spaces and replace with one space code example Example: remove extra space in string js newString = string.replace(/\s+/g,' ').trim();