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