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