How to replace all dots in a string using JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

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>
raja
Published on 27-Feb-2018 15:12:51
Advertisements