I have a string with multiple different HTML characters in it.
For example:
var price = "CHF 150.– (brutto)";
how can I replace the HTML entities like –
with the string character like below?
"CHF 150.- (brutto)";
I have a string with multiple different HTML characters in it.
For example:
var price = "CHF 150.– (brutto)";
how can I replace the HTML entities like –
with the string character like below?
"CHF 150.- (brutto)";
3
Answers
You can use the method
replace()
like so:MDN Web Docs – String.prototype.replace()
You could decode it using the native
DOMParser
.I created a wrapper class that can be reused: