javascript replace all occurrences of space in a string code example Example: js replace all spaces var replaced = str.replace(/ /g, '_');