convert string to utf-8 in javascript

Viewed 13846

I am having hundeausführer (in German) text in URL and it is giving me as hundeausf%C3%BChrer in console.log. How can I convert hundeausf%C3%BChrer back to hundeausführer?

I tried

console.log(unescape(encodeURIComponent('hundeausf%C3%BChrer')));
console.log(decodeURIComponent(escape('hundeausf%C3%BChrer')));

but not getting a proper answer in the console log. Getting the same text as hundeausf%C3%BChrer

Anyone help me to solve this out?

2 Answers

Use the decodeURI() function

console.log(decodeURIComponent('hundeausf%C3%BChrer'));

>>hundeausführer

This works for me.

console.log(decodeURI('hundeausf%C3%BChrer'));

Related