-1

I am getting a data from an API to my JS project. Data is about questions and answers. Texts in data are broken. Sometimes there are special characters in questions or answers.

For Expample :

Question : Which song in rapper Kanye West's album "The Life of Pablo" features Rihanna?

Following special characters are characters I've been able to catch so far. So maybe there is more in API data.

°
"
°
'
ö
’
é

The solutions that I've found on the internet was only focusing specific special character and solving it with .replace() function.

I want to ask you "Can you write the following function in JavaScript?"

function fixText(text){
 text = text.......??????
 return text
}
  • These are *HTML entities* that you need to decode. Preferably don't have the API return HTML-encoded text to begin with…?! – deceze Jun 03 '22 at 10:59
  • Assuming your goal is to display the text: https://jsfiddle.net/fxzLdhj4/ – ChrisG Jun 03 '22 at 10:59
  • @ChrisG I am getting this API's data in react so the text is not same like in your example. It is directly come out with special characters – Mehmet Güdük Jun 03 '22 at 11:05
  • @deceze unfortunately – Mehmet Güdük Jun 03 '22 at 11:05
  • https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml (also kind of funny that the one time React turns out to actually be relevant, the question isn't tagged with React :P ) – ChrisG Jun 03 '22 at 11:06
  • @ChrisG I thought I added React tag already sorry about that. But the solution that you ve shared is worked! Thanks a lot – Mehmet Güdük Jun 03 '22 at 11:12

0 Answers0