I am trying to replace a string with multiple $
symbol in JavaScript using replace function. But all of the $
symbols are not getting written.
For eg:
var a = "xyz";
a = a.replace("xyz", "$$$");
console.log(a)
Output:
$$
I am trying to replace a string with multiple $
symbol in JavaScript using replace function. But all of the $
symbols are not getting written.
For eg:
var a = "xyz";
a = a.replace("xyz", "$$$");
console.log(a)
Output:
$$
The $
symbol has special meaning when used inside String.replace
. You can escape it by doubling it:
var a = "xyz";
a = a.replace("xyz", "$$$$$$");
console.log(a)
$
is a special character. so you have to use additional $ for each of them
var a = "xyz";
a = a.replace("xyz", "$$$$$$");
console.log(a)