Reputation: 3850
How do I replace +
with \+
using the replace method?
console.log("abc+pqr".replace("+","\+"));
This gives the original string abc+pqr
but I want abc\+pqr
.
How do I get this?
Upvotes: 0
Views: 41
Reputation: 6180
You need to escape the backslash:
console.log("abc+pqr".replace("+","\\+"));
Upvotes: 3