Skip to main content
1 of 4
HarshWombat
  • 169
  • 2
  • 2
  • 9

How do I replace all spaces, commas and periods in 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