Skip to main content
4 of 4
edited title
HarshWombat
  • 169
  • 2
  • 2
  • 9

How do I replace all spaces, commas and periods in a variable using javascript

I have tried var res = str.replace(/ |,|.|/g, ""); and var res = str.replace(/ |,|.|/gi, "");. What am I missing here?

var str = "Text with comma, space, and period."; var res = str.replace(/ |,|.|/g, ""); document.write(res);

HarshWombat
  • 169
  • 2
  • 2
  • 9