replace all spaces in string html js code example Example: javascript replace all spaces var str = 'a b c'; var replaced = str.split(' ').join('_');