Computer >> Computer tutorials >  >> Programming >> Javascript

How to replace all dots in a string using JavaScript?


To replace the dots in a string, you need to escape the dot (.) and replace using the replace() method.

Example

You can try to run the following code to replace all dots in a string −

<!DOCTYPE html>
<html>
   <head>
   </head>
   <body>
      <script>
         var str = 'Demo.Text.with.dots';
         document.write("Text with dots- "+str);
         
         var res = str.replace(/\./g,' ');
         document.write("<br>Text without dots- "+res);
      </script>
   </body>
</html>