<script>
var text = "a's ..a's ...\"... ";
text = convert(text);
function convert( text )
{
var n = text.replace(/\'/g, "'");
n = text.replace(/\"/g,""");
return n;
}
console.log(text);
document.write(text);
</script>
The problem is that when it replace the second time it take doesnt “remember” what it replaced the first time, so only the last replace is returned.
That’s because you are replacing the original
textstring in the secondreplace, instead ofn, which is the value of the replaced text:replacedoes not modify your original string. Instead, it returns a new modified string . You can also do both replaces in a single statement: