javascriptregexcharacter-replacement

Javascript: How to replace all "\" character to ""


I try to replace "\" character to empty "" but I can't do it. How to solve it?

Here is my code

abc = abc.replace('\','');

Solution

  • to replace all occurrences in a string you need to use a regex with the g flag,

    abc = abc.replace(/\\/g, '');