javascript remove all extra spaces code example
Example 1: javascript remove all spaces from string
str = str.replace(/\s/g, '');
Example 2: remove extra space in string js
newString = string.replace(/\s+/g,' ').trim();
str = str.replace(/\s/g, '');
newString = string.replace(/\s+/g,' ').trim();