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