How to convert unicode in JavaScript?

Below is a simpler way thanks to modern JS .

ES6 / ES2015 introduced the normalize() method on the String prototype, so we can do:

var directions = "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eEnggårdsgade\u003c/b\u003e";

directions.normalize();

//it will return : "Turn <b>left</b> onto <b>Enggårdsgade</b>"

Refer to this article : https://flaviocopes.com/javascript-unicode/


Those are Unicode character escape sequences in a JavaScript string. As far as JavaScript is concerned, they are the same character.

'\u003cb\u003eleft\u003c/b\u003e' == '<b>left</b>'; // true

So, you don’t need to do any conversion at all.


you can use JSON.parse directly on JSON response then the unicode characters will automatically converted to its html counter parts (\u003c will be converted to < sign in html)

JSON.parse(JSON.stringify({a : 'Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eEnggårdsgade\u003c/b\u003e'}));