The replace() method returns a new string with some or all matches of a pattern replaced by a replacement.
<!DOCTYPE html> <html> <body> <script> var str = 'hello "friend" what\'s up?'; console.log(str.replace(/\"/g, '\\"')); </script> </body> </html>
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.