PackOf20
PackOf20

Reputation: 334

Javascript : Remove special symbols from string

I'm trying to remove this special symbol § from a text but JavaScript won't seem to recognize it. So it wouldn't remove it at all. The only solution I've tried is this, with no luck:

var x = "Hello § How Are You §";
x = x.replace('§', '');
console.log(x);

And this is the console output I receive:

Hello § How Are You §

But when I remove any other regular character that can be found on a keyboard, it works normally. For example:

var x = "Hello § How Are You §";
x = x.replace('H', '');
console.log(x);

And this is the console output I receive:

ello § How Are You §

Is there any solution to this issue?

Upvotes: 0

Views: 1174

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521178

Strings are immutable in JavaScript. You need to assign the replacement to x. In addition, if you want to remove all § symbols, you may use a global regex replacement.

var x = "Hello § How Are You §";
x = x.replace(/§/g, '');
console.log(x);

Upvotes: 3

Related Questions