how to get rid of spaces in string javascript code example Example: javascript remove all spaces from string str = str.replace(/\s/g, '');